Getting YTD figure in SSRS report with filtered column group on year/month - sql-server

I have a Reporting Services report which shows a bunch of KPI scores. Each KPI has it's own Row on the report and for each row we show the SUM or AVG (depending on KPI type) score for last 3 years, and then a SUM, AVG or (ideally) total YTD figure per month in the current year:
KPI 2009 2010 2011 Jan Feb Mar Apr May etc.
Bagels Eaten (Total) 100 90 70 10 20 9 13 14
Sandwiches (Cumm. YTD) 90 75 86 13 23 46 65 76
The problem I'm seeing is that the RunningValue function appears to be working across rows, instead of within the filtered column group and current row that makes up the Jan, Feb, Mar columns (monthly data, grouped by year and month, filtered on current year). So the output is not as above, instead its a fairly random figure based on all the values in the rows (I'm sure it's not random it just looks like it is).
The Column Group is called "MonthNum" and the Expression for the cell value decides which aggregation to apply based on an "AggregationType" value in the source data:
=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value),
Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value),
Fields!AggregationType.Value="YTD",
RunningValue(Fields!ScoreValue.Value,Sum,"MonthNum"))
Any help much appreciated
Update:
Here is an example few rows (scores per month, per kpi) of the data set being used (formatting is a bit tricky!). Items with aggragation type 'YTD' would have the cummulative YTD expression applied, everything else would be SUM for the current month:
KpiID Title KPIOwner ScoreValue YearNum MonthNum ReportingGroupTitle ScoreType DisplayOrder DisplayPrecision UnitOfMeasure AggregationType
5 Donuts Served Donut Manager 35 2007 1 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 42 2007 2 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 86 2007 3 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 14 2007 4 Catering Services Actual 10020 0 Number YTD
6 Donuts Cooked Donut Manager 45 2007 1 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 48 2007 2 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 93 2007 3 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 32 2007 4 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 18 2007 5 Catering Services Actual 10020 0 Number SUM

From what I understand from your question this is what I would do:
Assuming that when the aggregation type YTD returns the acumulated totals until (and including) the MonthNum.
Create a Matrix with two a groups on KpiID and a child group on AggregationType, and two column groups (adjacent) one on the year and one on the month (on the year group, create a filter so that you don't include the current year and on the month group exclude the values where the year is not the current one).
Then you can use the following expression, for both the year and the month group (the last will give you the YTD value for the last month in each year)
=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value),
Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value),
Fields!AggregationType.Value="YTD", Last(Fields!ScoreValue.Value))

Related

Aggregate metric per date

I have a data source with data formatted like this:
ID
Visits
Charges
Date
Location
33
21
375
2022-01-29
A
34
4285
4400
2022-01-29
B
35
12
2165
2022-01-29
C
36
31
4285
2022-01-30
A
37
40
5881
2022-01-31
A
38
29
4715
2022-01-31
B
39
8
1390
2022-01-31
C
I want to get the aggregated visits of all locations per day, and from there getting the Max value of a day for the time period chosen by the user on a ScoreCard and a Table. At the moment when i choose the max value of the metric visits it only gives me the max value of column (4285), not for the aggregated data per day.
The value i am looking for, in the time period between 28-01 and 31-01 should be 4318 (the sum of all 3 locations for the 29-01, which is the highest of the 3 days)
Thanks!
What I may suggest is to use Pivot Table like this:
You choose Date as your row dimension. Then you choose Visits as metric (aggregation set as SUM).
Remember to sort this table by Visits in descending order. Your maximum value should be on top. If you want to see only this maximum value, you can change size of your pivot table to keep only first value visible.
This should work with additional controls too.

SQL Query for Pagination

I have students data for their fees paid for each program, now I want to show the outstanding fees, now since it's possible student could have their outstanding fees for 2018, 2019 and 2020 pending, hence it will have 3 rows (The months will be in columns). Now since the student is same, I will be clubbing the records in the front end, now if I consider pagination and I have 10 per page limit, and in these 10 records 3 records is of the same student (since year was different), in that case I will end up having just 7 records on given page.
Here's the sample data.
Studentname RollNo Year Program Jan Feb Mar Apr May Jun ...
abc 1 2018 p1 200 50 10 30 88 29
abc 1 2019 p1 100 10 20 50 12 22
abc 1 2020 p1 30 77 33 27 99 100
xyz 2 2020 p2 88 29 32 99 199 200
How could I manage pagination for above case.
Assuming your front end is HTML/CSS/Javascript:
You don't need to handle pagination in your query - or even your backend - at all. Everything can and should be done on your frontend. I would suggest using JQuery and Bootstrap to create a paginated table to display your data using Material Design for Bootstrap

How to sum SSRS Matrix Columns on Row Group

I have a report that displays the total hours a person worked for each project they are assigned to, aggregated on month. I would like to sum the total hours for each person, for each month, in SSRS 2008 R2. So, for example, I have the follow data and would like to column totals like so:
January February March
Worker 1
Project1 50 80 20
Project2 30 10 60
Project3 10 40 5
Total: 90 130 80
Worker 2
Project1 20 40 60
Project2 10 30 10
Porject3 30 10 50
Total: 60 80 120
Everything I have tried so far either sums each column for all workers combined (summing by 'Month' column group) or sums all hours for each worker (Summing by 'Person' row group).
For completeness, my row groups are:
Person
Project
RowGroup
My Column groups are:
Month
ColumnGroup
I know that I can create another query/data set to do this, but I was hoping that SSRS can do this fairly easily. It seems like a trivial problem and perhaps I am just missing something.
Any help would be great or perhaps this is something that SSRS can't do.
If you are trying to add a Column containing totals, it is pretty simple just
right click on cell --> Totals --> Column
As shown here

Time series ordering

I have a 200 data files to process. I need a solution for one of the files and I would do same for the rest of the files. It is a typical daily time series problem.
My rainfall data is arranged thus: 1990 to 2011 as years, under each year are 12 months, and in front of each month are 29 or 30 or 31 days depending on the month.
My problem is to take all the days in each month and place them beneath that month and for each year. The result will be two column vectors; one for dates and one for rainfall on each day, in each month in each year.
Thanks in advance.
Asong.
my data is shaped as:
1960 1 2 3 4 5 6 4
1961 1 2 3 4 5 6 4
and I want it to be 1960
1
.
.
N
1961
1
.
.
N
etc. as a column not row form.
I got the answer using reshape(a.',1,[]).
However, one problem remains. My data contains 31 days in all months. How can I tell matlab to delete last two or three days in February and one day in April and other months which are supposed to have 30 days but have 31 in my time series?

Microsoft SSAS Average Calculation in Cube

I m very new to cube development in SSAS. I m using Microsoft BIDS 2008.
I have built a small cube, which is as mentioned below:
India Pakistan GrandTotal
Apr 6 10 16
May 5 6 11
I want to add a field called as average to be added beside Grand total
India Pakistan GrandTotal Average
Apr 6 10 16 8
May 5 6 11 5
Any inputs on this would be helpful. 5.5 in average is truncated to 5.
Thanks !!!
Create a calculated member that divides current measure by the count of members in your measure group (normally a count measure is automatically created when you add a measure group).
Truncation can be handled by the FORMAT_STRING property of that calculation or by using MDX functions.
More info on calculated members:
http://technet.microsoft.com/en-us/library/ms166568(v=sql.105).aspx

Resources