Does the iif function compute both paths in SSRS or is it short-circuited?

对着背影说爱祢 提交于 2019-11-26 15:28:59

You're right, it doesn't short circuit. That sucks.

You'll have to do something like this:

= Iif(KgSold = 0, 0, Revenue) / Iif(KgSold = 0, 1, KgSold )

The switch function should also work.

This happens because in VBScript all conditions within an IIF will be evaluated first before any functionality occurs.

Add the following to your code:

Public Function SafeDiv(byval num as double, byval den as double) as object

    If den = nothing then return nothing
    If den = 0 then return nothing

    return num / den

End Function

Then call

=Code.SafeDiv(Revenue,KgSold) 

in the text box epression

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