本文介绍了除以零时如何消除 SSRS 表达式上的#error?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 SSRS 报告中除以零时消除 #error.我有以下表达式仍然给出 #error

I am trying to eliminate #error when dividing by zero on my SSRS report. I have the following expression which still gives #error

=IIf(IsNothing(Lookup(Fields!id.Value, Fields!id2.Value, Fields!Stock.Value, "Models")),
88 , Fields!QTY_AVL.Value * 100 /
Lookup(Fields!id.Value, Fields!id2.Value, Fields!Stock.Value, "Models"))

但是,如果将/切换为 * ,如下所示,我正确地得到了值 88

However if switch the / to * , as below, I correctly get the value 88

=IIf(IsNothing(Lookup(Fields!id.Value, Fields!id2.Value, Fields!Stock.Value, "Models")),
88 , Fields!QTY_AVL.Value * 100 *
Lookup(Fields!id.Value, Fields!id2.Value, Fields!Stock.Value, "Models"))

在这两种情况下,我得到的正确值是查找值 > 0

In both instances I get the correct value is the lookup value > 0

(Fields!QTY_AVL and Fields!Stock come from different sources)

我是否遗漏了一些明显的东西?对此的任何见解都非常感谢.

Am I missing something obvious? Any insight into this much appreciated.

推荐答案

如果您转到报告属性",然后单击代码",然后在表达式中将其引用为 CODE.SafeDivide(Value1, Value2),根据需要添加参数.

You can add a safe divide function if you go to Report Properties and then click Code, then reference this in your expression as CODE.SafeDivide(Value1, Value2), adding the parameters as necessary.

此函数将返回 0 而不是显示 #error 消息.

This function will return 0 instead of displaying the #error message.

Public Function SafeDivide(ByVal Numerator As Decimal, ByVal Denominator As Decimal) As Decimal
    If Denominator = 0 Then
        Return 0
    End If
    Return (Numerator / Denominator)
End Function

这篇关于除以零时如何消除 SSRS 表达式上的#error?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 19:16