Create a column within an SSRS Report to sum values based on conditions of previous column - sql-server

I have an ssrs report that shows revenues for each month of a year for several years based on start and end date parameters the user enters. What I would like to do is add a second column that shows the revenue for that quarter (march would show q1 revenue, june q2 etc). the problem I am having is that I am able to do this for a single year but once the query starts looking at multiple years my column shows the value for all 1st quarters regardless of year. The picture shows what I am currently getting. Any recommendations on how to fix my expression to also look at the year value when summing these quarters?
Here is the code I am using to only populate the quarter column based on the month.
=IIF(Fields!Sort_Order.Value=3,
Sum(Lookup(1,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(2,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(3,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
IIF(Fields!Sort_Order.Value=6,
Sum(Lookup(4,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(5,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(6,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
IIF(Fields!Sort_Order.Value=9,
Sum(Lookup(7,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(8,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(9,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
IIF(Fields!Sort_Order.Value=12,
Sum(Lookup(10,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(11,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
+Sum(Lookup(12,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),""))))

I ended up creating a quarter column within my data set that was then used as a parent group for the month rows. I then hid that column and added a total for the quarter that gave me sub totals. Not exactly what I was looking for but gave me the result I needed.

Related

How to get a YTM calculation instead of YTD in Google Data Studio

I have an earnings table in my Google Data Studio report from January 21 - YTD.
But what i want is a table that shows me YTM (so this year until last month) Jan-21 til Sep-21 and that dynamicly on 1st Nov, Okt-21 is added to the table, and on 1st dec Nov-21
is added etc.
Because the Total YTD value is other wise too high, due to cost being booked at the end of the month and earnings through the month.
Filters wont let you do it dynamicly,
date range filters same,
always possible to do it manualy with date range but this i cannot ask from my client.
any suggestions??
Kind regards
I found the answer,
i left the question for when someone else wants to do it,
it is actualy simpel fixed by using advanced date filter and then leaving the start date on 1-jan, and end date to today minus 1 month.
this gave me the exact result i needed yt last month

Data Studio - Grouping by Week

I have a simple Data Studio table consisting of two columns. The first column is the week (ISO Year Week) and the second column is the total registrations we've received for that week.
However, my Week column repeats 7 times (7 Rows) for each week as it's counting by day within that week. See below:
Is there any way to get this to group by the listed week? Below are my settings:
Dimension = Conversion Date set as "ISO Year Week" for the type.
Metric = Equals the count of Conversion Date (Same Conversion Date field used for dimension)
Any help would be much appreciated.
There might be an issue with the date format of the source. Without knowing the source (e.g. Google Analytics or Sheets) it’s hard to tell.
Blended Data
I recently had this issue with blended data. The response of a similar question helped me to find a way.
Basically you have to add a new custom field to the data source with the formula WEEK(date_field_link). Data studio will recognise this as a date in compatibility mode, but for me it still works. Then you can use this new date field as a join key to blend the data while grouping it in weeks.
Normal Data
If this problem appears in a regular non-blended dataset you might want to check if Data Studio correctly catches the date as a date. This help article from Google might be worth checking out: https://support.google.com/datastudio/answer/6401549?hl=en#zippy=%2Cin-this-article
I made a similar case work using blended data.
Your column "Conversion Date" repeats the same week 7 times because it's just a display value. Every row has a date value (year, month and a day) but you're just showing the corresponding week. So, data-studio treats them as different data and doesn't group them.
To be able to group them by Week you need to create a new field with a value containing only the week and the year. So, you can use the formula
YEARWEEK(your_date)
The resulting Date will be groupable.
NB1: If your date isn't of the type Date, you can parse it from text to date using
the method:
PARSE_DATE("%Y-%m-%d", your_date_text)
NB2: If the created field has the type number and doesn't show the possibility to change type to Date, you can do this trick: (it's weird but it works):
First type as a formula for the created field and apply:
MONTH(your_date)
This will unlock the compatibility Date types. You can choose from them the ISO Year Week type.
and then change the formula from MONTH(your_date) to YEARWEEK(your_date) [your formula] as I explained above. The chosen date type won't go away even if it wasn't available the first time.

Is there a way to consolidate multiple formulas into one

all:
I am trying to design a shared worksheet that measures salespeople performance over a period of time. In addition to calculating # of units, sales price, and profit, I am trying to calculate how many new account were sold in the month (ideally, I'd like to be able to change the timeframe so I can calculate larger time periods like quarter, year etc').
In essence, I want to find out if a customer was sold to in the 12 months before the present month, and if not, that I will see the customer number and the salesperson who sold them.
So far, I was able to calculate that by adding three columns that each calculate a part of the process (see screenshot below):
Column H (SoldLastYear) - Shows customers that were sold in the year before this current month: =IF(AND(B2>=(TODAY()-365),B2<(TODAY()-DAY(TODAY())+1)),D2,"")
Column I (SoldNow) - Shows the customers that were sold this month, and if they are NOT found in column H, show "New Cust": =IFNA(IF(B2>TODAY()-DAY(TODAY()),VLOOKUP(D2,H:H,1,FALSE),""),"New Cust")
Column J (NewCust) - If Column I shows "New Cust", show me the customer number: =IF(I2="New Cust",D2,"")
Column K (SalesName) - if Column I shows "New Cust", show me the salesperson name: =IF(I2="New Cust",C2,"")
Does anyone have an idea how I can make this more efficient? Could an array formula work here or will it be stuck in a loop since its referring to other lines in the same column?
Any help would be appreciated!!
EDIT: Here is what Im trying to achieve:
Instead of:
having Column H showing me what was sold in the 12 months before the 1st day of the current month (for today's date: 8/1/19-7/31/20);
Having Column I showing me what was sold in August 2020; and
Column I searching column H to see if that customer was sold in the timeframe specified in Column H
I want to have one column that does all three: One column that flags all sales made for the last 12 months from the beginning of the current month (so, 8/1/19 to 8/27/20), then compares sales made in current month (august) with the sales made before it, and lets me know the first time a customer shows up in current month IF it doesn't appear in the 12 months prior --> finds the new customers after a dormant period of 12 months.
Im really just trying to find a way to make the formula better and less-resource consuming. With a large dataset, the three columns (copied a few times for different timeframes) really slow down Excel...
Here is an example of the end result:
Example of final product

I need to provide a tabulated output of this month, month+1, month +2, and month +3 derived from numerous tables within the one sheet

The History:
I have a data set that refreshes every Monday morning adding last week's values to a growing tally until there is 52 weeks in the data set (9 separate cohorts), across 38 different departments.
I have built a power query to filter the department and compiled tables for each cohort, limiting the data to the last 17 weeks, and using excel forecast modelling then setup each table to forecast 16 weeks ahead.
Because the week beginning (WB) dates keep changing IO cant hard code the result table to cells within each cohort table.
My result table needs to show current month, month +1, month +2, and month +3 forecast values as per the highest date closest to or equal to EOM and I need this to be automated, hence a formula.
PS added complexity is that the table has date/value adjacent in (last 17 weeks) and columns separated in future 16 weeks of data in each table. Structure is exactly the same across all the 9 cohort forecast tables.
My Question:
Am I best to use a nested EOM formula, or VLOOKUP(MAX) based on the cohort_forecast_table image link below?
Because the current month needs to be current I have created a cell using =NOW().
I then complete a VLOOKUP within each cell in the master table that references the references the data in each sub-table usin MAX and EOMONTH for current month, then month+1, month+2, month+3, etc.
In a simplified broken down solution:
Date array = 'D3:D35'
Volume array = 'E3:E35'
End of current month formula cell B3: =MAX(($D$3:$D$35<EOMONTH(D1,0))*D3:D35)
Call for result in cell C3:
'=VLOOKUP(B3,Dates:Volumes,2,FALSE)'
I think this will work for me and thank you all...

How to Eliminate #Error Columns in Tablix Crosstab Group

Imagine a one-table query that accepts a year (range) as a parameter and then yields a dataset grouped by State, City, and Month, with a count of UFOs, if any, for each month.
Tie that dataset to an SSRS Tablix, with a crosstab layout:
The Row Groups are State, City;
The Column Group is the Month (Jan through Dec); and
The row-column intersections are the # of UFOs sighted, if any.
PROBLEM:
If I run the (parameterized) report for one location, even one with few sightings, all goes well: I see columns only for months with sightings.
However, if I report more than one location (say, "Albany," with daily sightings, and "Troy," with October-only), Troy's grouping will come out ugly: If reported alone, just the October column would show, but, now, October along with 11 columns of "#Error" for the month name and a "0" for UFO count appear.
I suspect that one solution may involve some 0- or NULL-fill of missing-month data for Troy and other cities (How?), but is there some other way, via the Tablix widget, to achieve the desired result?
I don't understand what you're doing wrong but the matrix usually works with filling the headers correctly and leaving blanks where there is no data for a single group.
It might help if you show your design view.
Design View:
Report View:
Many of the users don't have data for previous months but at least one does so the month is displayed in the header. The blanks are where there is no data for that month/user combo.
I don't see why your report isn't working like this. If I only selected one user, then only the months that user had will be displayed.

Resources