问题
=IIf(Sum(Fields!CUSTOMER_PROFIT.Value) <= 0 Or Sum(Fields!REVENUE.Value) <= 0,
"N/A",Round(Sum(Fields!CUSTOMER_PROFIT.Value)/Sum(Fields!REVENUE.Value)*100,2))
The sample output is as follows:
customer profit revenue customerprofitability
105003.73 227912.88 46.07
-8560.57 0.00 #Error
610.53 -1306.0 N/A
why is that when divided by zero gives #error but when divided by a negative value gives N/A ? I do not want #error to occour in the customerprofitability column. Appreciate any help!
回答1:
SSRS will evaluate your expression fully, even though you want it to stop after the 'true' part of your iff statement.
Therefore you need to make the 'fail' part of the iff statement mathematically sound for all rows (currently if fails with divide by zero on the second row).
This should give you your desired result
=IIf(
Sum(Fields!CUSTOMER_PROFIT.Value) <= 0
Or Sum(Fields!REVENUE.Value) <= 0,
"N/A",
Round(Sum(Fields!CUSTOMER_PROFIT.Value)/IIF(Sum(Fields!REVENUE.Value)= 0, 1,Sum(Fields!REVENUE.Value))*100,2
)
)
来源:https://stackoverflow.com/questions/7078586/ssrs-expression-throws-error-possible-reasons