开发者

SSRS expression throws #Error - Possible reasons?

=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      cus开发者_如何学编程tomerprofitability  
 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!


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
   )
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜