iif 函数计算 SSRS 中的两条路径还是短路?
我正在尝试根据产品的销量评估每公斤的价格(美元/公斤)。 如果产品在指定期限内实际售出,则此方法效果很好。 但是,如果产品未售出,Kg(分母)最终将变为 0(零)并产生错误。 - 除以零误差。
我尝试了这个
=iif(KgSold=0,0,Revenue/KgSold)
看来 iif 函数正在计算 true 和 false 结果。 我该如何解决这个问题。
我应该使用 switch
函数吗?
=switch(KgSold=0,0
KgSold<>0,Revenue/KgSold)
I am trying to evaluate a Price per Kilo ($/Kg) based on sales of a product. This works fine if the product was acutally sold during the period specified. However if the product is not sold the Kg (the denominator) ends up being 0 (zero) and an error results. - Divide by Zero error.
I tried this
=iif(KgSold=0,0,Revenue/KgSold)
It appears that the iif
function is calculating both the true and false results. How do I get around this.
Should I be using the switch
function instead?
=switch(KgSold=0,0
KgSold<>0,Revenue/KgSold)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是对的,它不会短路。 太糟糕了。
您必须执行以下操作:
switch 功能也应该起作用。
You're right, it doesn't short circuit. That sucks.
You'll have to do something like this:
The switch function should also work.
发生这种情况是因为在 VBScript 中,在发生任何功能之前,将首先评估 IIF 内的所有条件。
This happens because in VBScript all conditions within an IIF will be evaluated first before any functionality occurs.
将以下内容添加到您的代码中:
调用epression
然后在文本框中
Add the following to your code:
Then call
in the text box epression