简体   繁体   中英

SSRS Calculated field with IIF expression gives #error when the condition is false

Hello I'm fairly new to SSRS and I'm working on making my first report for work. It has been going fine until today when I needed make a textbox in Tablix handle both a numbers calculation and text. A column in my SQL table that was previously a purely number field now has n|a for certain rows. So I wrote the following expression to handle those n|as. When the proceeds field is numeric the formula works, but when it's an n|a it shows up on the report as #error and I can't figure out why. I've removed all formatting from the textbox to the same result.

=IIF(Fields!Proceeds.Value<>"n|a",Fields!Proceeds.Value / Fields!DealBalance.Value,"n|a")

As TnTinMn explained, IIF always evaluates both the true and false part of the expression.

The simple fix is to do something like EDIT Revised due to update from OP

=IIF(Fields!Proceeds.Value<>"n|a",VAL(REPLACE(REPLACE(Fields!Proceeds.Value,",",""),"$","")) / Fields!DealBalance.Value,"n|a")

This simply strips out the $ symbol and commas and then converts the text to a number using VAL(), if the text is not a number it will return zero which will not cause an error as the false part of your expression would give 0/DealBalance.

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