views:

418

answers:

3

In SSRS 2008 I am trying to maintain a SUM of SUMs on a group using custom Code. The reason is that I have a table of data, grouped and returning SUMs of the data. I have a filter on the group to remove lines where group sums are zero. Everything works except I'm running into problems with the group totals - it should be summing the visible group totals but is instead summing the entire dataset. There's tons of articles about how to work around this, usually using custom code. I've made custom functions and variables to maintain a counter:

Public Dim GroupMedTotal as Integer
Public Dim GrandMedTotal as Integer

Public Function CalcMedTotal(ThisValue as Integer) as Integer
    GroupMedTotal = GroupMedTotal + ThisValue
    GrandMedTotal = GrandMedTotal + ThisValue
    Return ThisValue
End Function

Public Function ReturnMedSubtotal() as Integer
    Dim ThisValue as Integer = GroupMedTotal
    GroupMedTotal = 0
    Return ThisValue
End Function

Basically CalcMedTotal is fed a SUM of a group, and maintains a running total of that sum. Then in the group total line I output ReturnMedSubtotal which is supposed to give me the accumulated total and reset it for the next group. This actually works great, EXCEPT - it is resetting the GroupMedTotal value on each page break. I don't have page breaks explicitly set, it's just the natural break in the SSRS viewer. And if I export the results to Excel everything works and looks correctly.

If I output Code.GroupMedTotal on each group row, I see it count correctly, and then if a group spans multiple pages on the next page GroupMedTotal is reset and begins counting from zero again.

Any help in what's going on or how to work around this? Thanks!

A: 

I don't know where do you use this. but in your case, if I were you, I just use simple expression to check visibility of SUM

for example I'd use Right Click On Sum Box \ Select Expression \ then use IIF(SUM <> 0, sum. "")

It worked on every where and wont reset, in your case you have a Region and your code will reset in every region so you willface with serios isses if you don't change your way.

Nasser Hadjloo
A: 

Hi edmicman I am also having this same issue. Did you got any solution for this? If so can you please update the same in this forum.

sagargeo
It looks like I ended up getting frustrated and scrapped the whole idea - I changed my stored procedure to do the counting and reworked how I was doing the report. Bah to SSRS sometimes :-/
edmicman
A: 

Finally found the solution myself. Here it is, add Shared to the variable declarations:

Public Shared Dim GroupMedTotal as Integer
Public Shared Dim GrandMedTotal as Integer
John Strickler