SSRS Tablix report, handling column period totals and subreport comparisons - sql-server-2008

I'm new to SSRS (2008) and am trying to replicate an existing Access report. The report lists sales totals by month, and I've not had any issue resolving the basics into a tablix. However the original Access report then totals columns by quarter, 6 month and yearly values, and moreover applies incorporates subreports to compare these with previous year totals and targets. Schematically thus
Sale Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
Customer 1 1 11 10 8 1 2 0 0 0 1 3 4 40
Customer 2 0 1 3 1 0 0 0 1 1 0 2 1 10
MonthlyTotals 1 12 13 9 1 2 0 1 1 1 5 5 50
Quarterly 26 12 2 11
6 Monthly 38 13
Yearly 51
Prev Yr Totals 2 10 10 5 5 0 0 0 0 0 0 10
Monthly Diff -1 2 3 4 -4 2 0 1 1 1 5 -5
Quarterly Diff 4 2 0 10
And so forth. Note that the parameters are set so that the report can start at any month to lists the columns (for different financial years)
I have everything working fine for the first 4 lines (sale, customer 1, customer 2 and monthly totals) in the above, but cannot see the best way of
Displaying the quarterly etc totals
Displaying the subreports to show the previous years and target values with the differences between them and the current values.
I have full access to the SQL Server and am comfortable with complex queries and stored procedures, so was inclined to generate the values in a table and display out that, but is there a better way? In particular handling the quarterly etc totals in SSRS would be advantageous.

I think it is not possible to caclulate the quarterly totals with the help of Tablix alone, unless your SQL Table has a separate column named "Quarter".
So to achieve your requirement, you have to write simple stored-procedure which returns the resultant table along with one more additional column named "Quarter" which contains the values from "Q1..Q4" which is calculated based on the sales month field.
Then you can add this new column (Quarter) as ColumnGroup on top of your existing group in the tablix.
Hence the whole idea is to create the result set with all possible columns for which you want to group.

Related

How to split a string of yearly responses into columns for each year in MySQL?

I have the following table answer with the columns id, value, where value is a string with yearly information separated by comma:
id
value
1
0,2,3
3
1,3,0
In the case above, for id 1 the values represent 3 for 2021, 2 for 2020 and 0 for 2019. The latest year is always in the end.
How can I transform the result above into this table below?
id
year
value
1
2021
3
1
2020
2
1
2019
0
3
2021
3
3
2020
2
3
2019
0
I tried several examples similar to split() and explode() from other languages.

How to access counts to calculate the difference in a SSRS matrix with column and row groups

I’m building a report in Visual Studio 2017 (SSRS) and it uses a stored procedure that returns the following data:
PRODUCT_ID TYPE YEAR STATUS
15242 01 1516 ACTIVE
54541 02 1617 ACTIVE
64454 01 1516 INACTIVE
73697 02 1516 INACTIVE
98878 03 1617 ACTIVE
I needed to get the counts per status, per year, per type, so I started building a matrix with STATUS as first column group and YEAR as its child, then, in the row group I only have TYPE. In the data fields I only have the count, so it looks like this:
ACTIVE INACTIVE
1516 1617 1516 1617
01 1 0 1 0
02 0 1 1 0
03 0 1 0 0
My problem is the following. I want add a DIFF column (example below) that calculates the difference between the two years, but the problem is that since all is done dynamically, I don’t know how to access the text boxes with the counts to calculate the difference. I could build a stored procedure that calculates all those numbers, but it would be a slower solution since the field TYPE will grow over time.
ACTIVE INACTIVE
1516 1617 DIFF 1516 1617 DIFF
01 1 0 1 1 0 1
02 0 1 1 1 0 1
03 0 1 1 0 0 0
Any help will be appreciated. Thank you guys in advance.
I don't think you'll be able to make a matrix work the way you want without using a bunch of LookUps that would kill performance.
I would make a regular table and filter the data in the expression to separate the years. You'll have to figure out some logic based on your data to determine which year is the current and which is the last year.
You would use the same grouping for the TYPE as you do now.
Assumeing you have identified the previous can current year:
=SUM(IIF(Fields!YEAR.Value = Parameter!Current_Year.Value, 1, 0)
For the DIFF column, use
=SUM(IIF(Fields!YEAR.Value = Parameter!Current_Year.Value, 1, 0) - SUM(IIF(Fields!YEAR.Value = Parameter!Previous_Year.Value, 1, 0)
You could use a variable or a Field in your query to identify the current year - it doesn't need to be a parameter.
You could still use the matrix for your Statuses (Stati?) for the Active and Inactive.
I have found a way to calculate differences between matrix columns (available from SSRS 2008 and up) using the previous function. Look at my answer to this question. how to subtract adjacent columns in an ssrs matrix
how to subtract adjacent columns in an ssrs matrix

SSRS 2 column groups in matrix, 1 row reads from 1, the rest read from the other? (pls help)

Is there a way in SSRS to have an additional row within your row group, to look at a different column group than the rest of the row group
Let's say I have STATES, SALES, MONTH, and BUCKET_MONTH as my dataset fields BUCKET_MONTH is already calculated for me, based off of the MONTH. I want to show something like this:
SAMPLE DATA LIKE THIS FOR FLORIDA (and other months but BUCKET_MONTH only matters for florida let's pretend)
STATE MONTH SALES BUCKET_MONTH
FL JAN 50 FEB
FL FEB 125 FEB
FL MAR 100 MAY
FL APR 0 MAY
FL MAY 100 MAY
SSRS MATRIX MIGHT LOOK LIKE THIS: ?
| 2 groups ?
| MONTH
| BUCKET_MONTH (I can hide this header)
-----------------------------------
1 col group|
STATE | SALES
BUCKET | SALES <-- this row is only visibile for FL which I know how to do
EXPECTED RESULTS WOULD LOOK LIKE THIS
JAN FEB MAR APR MAY JUN JUL
---------------------------------------------------------------------
CA 100 300 150
FL 50 125 100 0 100
FL BUCKET 175 200 <-- BUCKET_MONTH**
MA 0 200 250 50
BUCKET_MONTH in ds shows FEB for the rows with Jan,Feb MONTH, and shows MAY for Mar,Apr, May MONTH
Is there a way to do this in SSRS? Where one of the rows looks at a different column group to establish what column to put the SUM of SALES in?
Much appreciation in advance!
You have to add BUCKET_MONTH as parent column group in your matrix.
Add BUCKET_MONTH in the Column Groups pane, then delete the created row in the matrix selecting Delete groups only option. Now add MONTH as child group in column groups pane.
Add STATE in rows group pane and add a row for bucket total.
Use this expression for BUCKET TOTAL:
=IIF(
Fields!BUCKET_MONTH.Value=Fields!MONTH.Value,
SUM(Fields!SALES.Value,"BUCKET_MONTH"),
Nothing
)
It should produce:
UPDATE: Expression updated taking in account that MONTH and BUCKET_MONTH fields are actually dates.
=IIF(
UCASE(format(Fields!BUCKET_MONTH.Value,"MMMM yy"))=
UCASE(format(Fields!MONTH.Value,"MMMM yy")),
SUM(Fields!SALES.Value,"BUCKET_MONTH"),
Nothing
)
Let me know if this helps.

Add together grouped rows into one value

I've got an issue where I've been presented data in this format from SQL, and have directly imported that into SSRS 2008.
I do have access to the stored procedure for this report, however I don't want to change it as a few other reports rely on it.
Project HoursSpent Cost
1 5 45
1 8 10
1 7 25
1 5 25
2 1 15
2 3 10
2 5 15
2 6 10
3 6 10
3 4 5
3 4 10
3 2 5
I've been struggling all morning to understand how/when I should be implementing the SUM() function with this.
I have tried already to SUM() the rows, but it still outputs the above result.
Should I be adding any extra groups?
Ideally, I need to have the following output:
Project HoursSpent Cost
1 25 105
2 15 40
3 16 30
EDIT: Here is my current structure:
"LineName" is a group for each project
You have to add a row group on "Project" since you want to sum up the data per each project.

Simple Line Graph in SSRS

I'm having issues using the line chart control in SSRS. If I was in excel this would be easy but for some reason I can't wrap my head around how to do it in SSRS
I'm returning 5 rows of data from a database and need to chart 3 of the rows.
Name J F M A M J J A S
1 Requested 13 19 4 20 2 0 0 0 0
2 Completed 1 0 0 4 1 0 0 0 0
3 % Completed .7 0 0 0.2 0.5 0 0 0 0
4 Monthly Ba 12 19 4 16 1 0 0 0 0
5 YTD Backlog 12 31 35 51 52 52 52 52 52
The rows consist of the name and the value for that month.
I'm trying to display a chart for rows 1, 2, and 5 that would look like a normal line graph with each of the Months being on the horizontal column and the value being the data point.
However, when I start adding things to my chart I'm getting 36 different series, one for each Month for each series and nothing seems to be working right. It's also splitting into Group 1 and 2 at the bottom which makes no sense to me. I feel like I'm missing something simple, most likely a grouping of some kind.
EDIT:
I ended up taking Nathan's suggestion and added an unpivot on the table to rotate the data into an acceptable format for SSRS
Thanks
Can you alter the query that is returning the results for the dataset?
If so try changing it so that the dataset looks more like this:
monthnumber month Requested Completed YTD Backlog
1 J 13 1 12
2 F 19 0 31
3 M 4 0 35
4 A 20 4 51
etc.
You should be able to add "Requested", "Completed" and "YTD Backlog" as Values and "month" as a Category to produce the chart you want.
I added a "monthnumber" column, as you will probably want something like this so that you can set the category (month) sorting expression to this, otherwise they will appear in alphabetical order.