SSRS: RunningValue() to get Cumulative Totals
If you have a SSRS (SQL Server Reporting Services) report, and you want to aggregate values on a column, the function RunningValue() is what you would use.
The function takes 3 parameters, the field you want to “run the value” on, the function you want to run on it (Sum for example), and then the scope. The scope can be “Nothing” ex: RunningValue(Fields!Blah.Value,Sum,Nothing) but where the scope really comes into play is when you want to group by given fields in your row.
So if you want to group by say, salesperson, and run their values by day of their sales for a month to date total, you would have
Salesperson Date Daily Sales Month To Date Sales
——————————————————————————-
Homer Simpson
07/01/2007 50 50
07/02/2007 43 93
Bart Simpson
07/01/2007 5 5
07/02/2007 8 13
How you achieve this is: on the row with the salesperson, there is a group defined if you right click. Look at the group name, by default it is usually table1_detailsGroup or something similar (if you used the wizard).
Then, the column for the Month to Date Sales would have the expression
=RunningValue(Fields!DailySales.Value,Sum,”table1_detailsGroup”)
Where you can see the scope is now defined as the table group name as a string.
Simlar Posts
- SSRS Exporting Report to Excel - Keep Formatting on Export
- SSRS and SSAS Formatting Dates
- SQL Server Reporting Services: Quick way to get 10 digit year (all the zero’s) using String.Format
- SSRS Exporting Report to Excel - Keep Formatting on Export Round 2
- Reporting Services Scripter: Sync Reporting Services Instances and Objects

February 1st, 2008 at 11:31 am
Hi Steve,
Thanks. I had searched for a while to get this right. Micorsoft documentation does not have a good example on RunnigValue.
As for the beer, let me know when you come to Toronto. I will definitely buy you one :-) .
Cheers,
Sena
April 14th, 2008 at 9:21 am
I can’t seem to set a scope. I’ve tried “table1_detailsGroup”, “table1_detailsGroup1″, “table1_Month” (which is the name of the details group)….only get an error message
April 14th, 2008 at 9:22 am
if you copied the statement from my blog directly, the quotes (”) get goofed up when you paste into SSRS. Just try writing it yourself, with quotes where they should be.
April 14th, 2008 at 9:45 am
I didn’t copy/paste. Here is my statement:
=RunningValue(Fields!Add_Remove.Value, Sum,”table1_Month”)
I’ve also tried =RunningValue(Fields!Add_Remove.Value, Sum,”table1_detailsGroup”)
My table is named table1 and I have two groups: Month and GroupByRegion.
April 14th, 2008 at 9:49 am
not sure then, it works for me, and others. Actually just came back here a week ago and used this again and it worked for me then, that is when I noticed the copy/paste didn’t work.
its tough to say without seeing the report/datasource, etc. but this does work.
April 14th, 2008 at 3:52 pm
got it to work….had to input scope as “Month” instead of “table1_Month”
Thanks…..runningvalue isn’t going to do what I want it to do anyway so I’m back to square 1……I have a whacky way I’m trying to aggregate my inventory data and I can’t seem to make it work like I want/need it to….thanks again!
PS Liked your songs (I write/record songs too…..don’t find many hackers that do so…..)
May 8th, 2008 at 5:20 pm
Slightly similar problem here… I have a column that is “quantity / sum(quantity)” in the detail section… I want the report to “sum” them up in the group footer. However, sum() cannot be nested. I tried using custom code and also runningvalue() — nothing works. Any help? Thanks.