Monday, January 5, 2015

SSRS 2008 R2 Report - Sum Totals of a Filtered Group

Hi Cyndi,


Based on my understanding, you specify a filter condition in group properties. Then you want to sum the filtered values for each field.


In this scenario, we need to specify a filter condition on group level. If we use sum() function out of group, the expression will calculate the total values on dataset level instead of group level. So we can’t simply use expression to achieve this goal. However, we can use custom code to record the filtered values for each field, then we can calculate the total based on these values. Please refer to the steps and screenshots below:


1. Add the custom code below into the report:



Public Shared Value1 as Integer=0
Public Shared Function GetValue1(Item as Integer) as Integer
value1= value1 + Item
return Item
End Function
Public Shared Function GetTotal1()
return value1
End Function
Public Shared Value2 as Integer=0
Public Shared Function GetValue2(Item as Integer) as Integer
value2= value2 + Item
return Item
End Function
Public Shared Function GetTotal2()
return value2
End Function

2. Design the tablix like below:



3. The result looks like below:



If you have any question, please feel free to ask.


Best regards,

Qiuyun Yu


No comments:

Post a Comment