简体   繁体   English

SSRS-如何对参数表达式求和?

[英]SSRS - How to sum a Parameter Expression?

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? 我在报表中使用以下参数作为表达式来提供1到7之间的数字。如何汇总此列?

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

Data is grouped by Season. 数据按季节分组。

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. 您将需要一些VB代码来汇总您的参数。

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. 我没有任何错误检查,因此,如果有无效值,则可能会出错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM