SSRS expression throws #Error - Possible reasons?

允我心安 提交于 2019-12-11 00:45:40

问题


=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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!