简体   繁体   中英

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

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?

This doesn't seem to be an issue with the IIF, but the datatypes seem to be mismatched. I have a few suggestions to try. First, you could try to multiply the true value by 1.0 as I assume the datatypes are decimal or double. The other option would be to use something like CInt to covert the value to the correct datatype. CInt would likely be inappropriate for decimals as it would round off any decimal values, but the idea is the same. Since your expression doesn't use any aggregates and only uses normal operators, it must relate to something other than the IIF .

Here's a useful link to break down the datatypes and conversion methods. Choose the most appropriate conversion and apply it to the 1 .

EDIT: The expression should be the following.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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