简体   繁体   English

在WHERE子句中带有参数的SSRS表达式

[英]SSRS Expression with parameter in WHERE clause

In SSRS, I'm trying to calculate the average number of months a client used a program. 在SSRS中,我试图计算客户端使用程序的平均月数。 The programID is the parameter for the whole report. programID是整个报告的参数。 I'm trying to achieve this (not written with real syntax): 我正在尝试实现这一点(不使用实际语法编写):

=Avg(Fields!length_of_stay.Value, 0))/30.0 WHERE programid = @ProgramID

Using this question, I came up the the following code which is producing an incorrect answer. 使用问题,我想出了以下代码,产生了错误的答案。 I tested in SSMS to get the actual values to compare to SSRS results. 我在SSMS中进行了测试,以获得与SSRS结果进行比较的实际值。

=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, 0))/30.0

The "/30" is used since the value is in days and I need months. 使用“ / 30”,因为该值以天为单位,我需要几个月。 I think the issue is using the parameter value chosen; 我认为问题是使用所选的参数值; this is my first report trying to calculate expressions with parameters. 这是我的第一份尝试使用参数计算表达式的报告。

Avg returns the average of all non-null numeric values. 平均返回所有非空数值的平均值。 0 is not null so it gets included in the average, distorting your result for every row with a different PragramId. 0不为null,因此它包含在平均值中,从而使具有不同PragramId的每一行的结果失真。 Try using Nothing instead: 尝试改用Nothing

=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, Nothing))/30.0

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

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