SSRS - How to sum a Parameter Expression?

1.6k views Asked by At

I'm using the below Parameter as an expression in my report to feed a number between 1 & 7. How do I sum this column?

=Parameters!NoofBookingsYear1.Value
Expression: [@NoofBookingsYear1]

Data is grouped by Season.

1

There are 1 answers

0
Hannover Fist On

Unfortunately, there's not a built in way to do this. Fortunately, there's Code to work around limitations. You would need some VB code to sum your parameter.

For your expression, you'll want to send all selected amounts of your parameter to the summing function:

=code.SumParam(Join(Parameters!q.Value, ", "))

For your code, you'll want to parse out the comma and add the numbers:

Function SumParam(Param as string) as Decimal

Start:
SumParam = SumParam + Val(Left(Param, INSTR(Param, ",") - 1))

Param = Mid(Param, INSTR(Param, ",") + 1, len(Param))

If INSTR(Param, ",") > 0 Then Goto Start 

SumParam = SumParam  + Val(Param)

End Function

I don't have any error checking, so if there's an invalid value, it will probably error out.