How to get a subquery total in SSRS - sql

I'm new to SSRS because I'm needing to do some more complex reports that are getting increasingly difficult/impossible in Crystal Reports. The initial report I'm working on involves getting a Trailing-Three-Month total for sales by salesperson grouped by week. Given a date range and a selected salesperson, I can get the basic report done with total sales grouped by year and week number (1-52).
However, for each of those weeks, I need to get the total sales for the 13-week period ending with that week. For example, for week # 20 - I need to show the total sales for weeks 8-20. On week # 21, I need to show the total sales for weeks 9-21. Etc.
I've managed to do some date formulas to calculate the starting & ending dates of the three month period. But what is the preferred way to get the subtotal of sales into the main report? In Crystal Reports, there was a way to pass a value from a subreport into the main report. But from what I understand, you can't do that in SSRS - subreports are "display only". Eventually, I will need to graph the TTM amount.
I've tried several methods, but I want to know what the best way is to get these kind of values? If I were writing code, it would just be nesting Do-While loops. What is the best method as far as complexity and/or performance?

Related

Tableau - Count Items in a Dimension based on what month they fall into

I am a newbie at Tableau (thought I have spent years working in R and Python), seems to be different in the way it handles things or I'm just not thinking the right way.
I have a data sources with training data (employees training and the status). The point is to build a dashboard that shows the % of training that is overdue. I have all of the logic for it, but I am stuck on something.
I have a calculated field to show me the total training due, then when I put that in a table, with a filter by year and a breakdown by month, I get the totals by month - good deal.
Now, I need to perform an year calculation (not the months, but the year based on a few different things), so my first step is I need to get the "Total Training Due" for December 2018. I have a dimension called "Due Month" which is a numeric (1,2,3,4, etc.) representing the month. So, based on what I have observed, I just need to do a little IF statement like so (keep in mind this is only for 2018 data right now):
IF [Due Month] = MAX[Due Month] THEN COUNT[Employee ID] END
I know this isn't the exact context, but it's sort of what I am looking for. So, for 2018, it would mean that, for all rows that are of month 12, I want to count those up (each row is a unique training requirement) and I want the total for the latest month in the data set. My overall goal is to create the calculation I need in a new sheet with a single calculated field (See the image below of the Excel spreadsheet and the J10 calculation). Then I can use a dashboard to combine everything. I thought about a total row at the bottom, but there isn't enough ways to change the totals to customize it to what I need. I figured I dashboard was the way to go and replicate each part it its own sheet.
I have seen so many suggestion for things like this, but not exactly this. I have tried many, but nothing that works. Here is the spreadsheet I am trying to replicate:
As you can see that calculation in J10 is kind of weird, no biggie for Excel, but I am struggling to replicate this in Tableau. Here is what I have in my Tableau so far, I'm 90% of the way there, I just need that last calculation. I have replicated the main table, and figure I'll do this J10 calc on a new sheet and just put them together on a Dahsboard. The only thing is, I want this to work when new data comes in, so I don't want to hard code any month numbers in there, I want it to be dynamic. Here is what I have on the tableau so far:
Thanks in advance!!
To get the value in Tableau that you have in F11 it's:
{FIXED [Due Year] : sum([Incomplete Overdue])}
You should be able to create that as another calculated field and then reference it, or include it directly in the Total Past Due Rate calculation.
This is an LOD calculation, the [Due Year] means that you only want the result dimensioned by the [Due Year] dimension, so you will get a different result for each year in the data source.
Thanks for this - after posting this, I was able to come up with this:
(TOTAL([Incomplete Overdue]) + SUM(IF ([Past Due]<0 AND INT([Due Month]) = {MAX(INT([Due Month]))}) THEN 1 ELSE 0 END)) / COUNT(IF INT([Due Month]) = {MAX(INT([Due Month]))} THEN [Employee ID] END)
Which works for the basic result I was looking for.

Q > SQL Business days for specific month/region

I am trying to write a sql query that would automate my reporting, I am pulling total renewal volume for month X and dividing it by the # of business days for that specific month (manual process for now). The issue that I am having and cannot seem to solve is that I report on two centers (Toronto & Montreal) and these two cities do not share the same holidays so depending on the month the # of business days will vary between cities.
The solution that I can think of is making a table within sql manually with a year or two ahead of the holidays for these 2 cities then sourcing the table, unless anyone else can suggest something better :).
Thanks in advance

SSRS chart grouping

My company makes various products that go through specific manufacturing steps.
I have an SSRS report that graphs the following per step: quantity today as a bar, and then markers of quantity yesterday, the goal for the day, how many items moved in to the step today and how many moved out.
In the chart data area, I have a category group of step and a sum of values of all of the numbers. I don't have anything in the series group area. (I'm using VS 2013, also.)
The users would like to add a grouping to quantity today -- a stacked bar by product by step, but still keep the rest the same (the quantity yesterday, goal, in and out would still be by step only).
I am not sure how or if I can group on something for one value, but not for the other values.
I've tried using the series groups, or adding another category group, but nothing is quite right.
Thoughts? Thank you!
I added two more fields to the dataset, in addition to quantity today -- quantity special and a calculated field of quantity today minus quantity special (the remainder).
I then modified the SSRS report to NOT chart quantity today, but chart quantity special and the remainder (in the values area). I changed these both to a stacked bar.
When there is no special data, quantity today- quantity special = the original. When there is, special + remainder = the total.

Calculated Member for Cumulative Sum

First some background: I have the typical Date dimension (similar to the one in the Adventure Works cube) and an Account dimension. In my fact table I have daily transaction amounts for the accounts.
I need to calculate cumulative transaction amounts for different accounts for different periods of time. The catch is that whatever is the first period shown on the resulting report should get its transaction amount as-is from the fact table and all the following periods in the report should have cumulative amounts.
For example, I might have a single account on rows and on columns I could have [Date].[Calendar].[Calendar Year].[&2005]:[Date].[Calendar].[Calendar Year].[&2010]. The transaction amount for 2005 should have the sum of transaction amounts that took place in 2005 for that specific account. For the following year, 2006, the transaction amount should be TransactionAmountsIn2005 + TransactionAmountsIn2006. Same goes for the remaining of the years.
My problem is that I don't really know how to specify this kind of calculated member in the cube because the end-user who is responsible for writing the actual MDX queries that produce the reports could use any range of periods on any hierarchy level of the Date dimension.
Hope this made some sense.
Teeri,
I would avoid letting the end-user actually write MDX queries and just force them to use ranges you defined. To clarify, just give them a start and end date, or a range if you will, to select and then go from there. I've worked with accounting and finance developing cubes (General Ledger, etc) for years and this is usually what they were ultimately looking for.
Good luck!

How do I automate a report on variance in the same SQL table fields on monthly basis?

I have a T-SQL view with integer fields. I need a report on a monthly basis regarding the difference from one month to the next, i.e. so many people were engaged in a particular activity on 8am of the 1st of this month, so many the previous month, here is the difference. The numbers fluctuate all the time. I need a variance between 2 snapshots in time.
I am using the SSRS, however in reporting services I can only display the "current" situation. I could run a report at 8am of the 1st of each month and then calculate the differences manually. But how could I automate this calculation and then report on the difference?
I have tried to import data from SQL to 1 Excel spreadsheet from 1 month, then to the 2nd spreadsheet from the 2nd month. The 3rd spreadsheet calculates the difference. But how do I create a nice looking report from Excel?
Additionally I cannot send the report by email. It has to be available online.
Furthermore, each office wants their figures to be confidential and not visible to another office.
Thanx in advance.
Can you add a UserCount table that stores each office's user count for each month? It could have columns like:
id
date
user_count
office_id
You would insert a new row each month based on what the view tells you that month for each office. Then it's as simple as exporting that table to Excel and graphing it using Excel's built-in graphing tools.