SSRS running Total On Multiple Columns?

user2721874 picture user2721874 · May 21, 2014 · Viewed 10.7k times · Source

I am creating one SSRS report in which I have one Tablix the data of that Tablix shown as below,

One Parameter --> Balance = 100

firstamt   SecondAmt   ThirdAmt    RunningTotal 
  10         15           20          145
  02         05           01          153
 -30        -20          -03          100

So basically my RunningTotal fields value should be

    RunningTotal = Balance + firstAmt+SecondAmt+thirdAmt and then update
    Balance =  Balance + firstAmt+SecondAmt+thirdAmt (Or RunningTotal)

and for then next row should use Balance= RunningTotal then calculate the next row runningtotal and so on. I tried using custom code, RunningValue but still got no luck.

Any help would be great, Thanks. And also my reporting server is 2008.

(In case of confusion feel free to comment.)

I tried following Custom code but it doesn't work

 public dim finalRunningTotal as decimal = 0
 public function CalculateRunningTotal (totalAmount as decimal, CheckAmount as decimal,pstAmount as decimal) as decimal
     dim valueToReturn as decimal = finalRunningTotal + totalAmount + CheckAmount +pstAmount 
     finalRunningTotal = valueToReturn 
     return valueToReturn 
end function

Answer

Ian Preston picture Ian Preston · May 21, 2014

Here's one of doing it - use an expression like:

=RunningValue(Fields!FirstAmt.Value + Fields!SecondAmt.Value + Fields!ThirdAmt.Value
        , Sum
        , Nothing)
    + Parameters!Balance.Value

You may have to change Nothing to a different Scope depending on how your table is set up.

Works for me in a simple example:

enter image description here

enter image description here

Here the example is as above.

enter image description here

enter image description here

To simplify this you could add a Calculated Field to the Dataset like:

=Fields!FirstAmt.Value + Fields!SecondAmt.Value + Fields!ThirdAmt.Value

Which makes the RunningValue expression simpler:

=RunningValue(Fields!MyCalculatedField.Value
        , Sum
        , Nothing)
    + Parameters!Balance.Value