'iif' condition is not working with Calculated Field in SSRS

时间:2019-04-08 13:35:51

标签: if-statement reporting-services expression calculated-field

For a dataset in SSRS reports, I've created a calculated field with below expression and it works fine.

=(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value

But sometime we can have factor value as 0. So, I modified above expression with below:

=iif(Fields!Factor.Value = 0,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*1,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value)

But this throws below exception: The Value expression for the textrun ‘Textbox2.Paragraphs[0].TextRuns[0]’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type.

Can someone please help to get resolve this issue?

1 个答案:

答案 0 :(得分:0)

这似乎与IIF无关紧要,但是数据类型似乎不匹配。我有一些建议可以尝试。首先,您可以将真实值乘以1.0,因为我假设数据类型是十进制或双精度。另一种选择是使用类似LogbackCustomAppender的值将值隐蔽为正确的数据类型。 CInt可能不适合十进制,因为它将四舍五入任何十进制值,但是想法是一样的。由于您的表达式不使用任何聚合,而仅使用常规运算符,因此它必须与CInt之外的其他内容相关。

Here's a useful link分解数据类型和转换方法。选择最合适的转化并将其应用于IIF

编辑:表达式应为以下内容。

1