我正在尝试计算方差百分比并避免除以0错误
以下代码适用于整体差异百分比
=IIf(Sum(Fields!Baseline.Value) = 0, 0, Sum(Fields!test.Value)) / IIf(Sum(Fields!Baseline.Value) = 0, 1, Sum(Fields!Baseline.Value))
我现在正尝试将其限制为某个类别并尝试使用以下表达式
=IIF(Fields!Category.Value = "Resources Capital ",
IIf(Sum(Fields!Baseline.Value) = 0, 0, Sum(Fields!test.Value))
/ IIf(Sum(Fields!Baseline.Value) = 0, 1, Sum(Fields!Baseline.Value)), 0)
它似乎没有查看类别值,因为它继续给我整体差异。任何帮助将不胜感激,因为我不知道从这里去哪里。
答案 0 :(得分:0)
您是否尝试将附加条件移至其他两个IIF表达式而不是添加另一个:
=IIf(Sum(Fields!Baseline.Value) = 0 and Fields!Category.Value = "Resources Capital ", 0, Sum(Fields!test.Value))
/ IIf(Sum(Fields!Baseline.Value) and Fields!Category.Value = "Resources Capital " = 0, 1, Sum(Fields!Baseline.Value)), 0)
答案 1 :(得分:0)
你必须在表达式的每个SUM中使用Iif
=
IIf(
Sum(IIF(Fields!Category.Value = "Resources Capital",Fields!Baseline.Value,0)) = 0,
0,
Sum(IIF(Fields!Category.Value = "Resources Capital",Fields!test.Value,0))
)
/
IIf(
Sum(IIF(Fields!Category.Value = "Resources Capital",Fields!Baseline.Value,0)) = 0,
1,
Sum( IIF(Fields!Category.Value = "Resources Capital",Fields!Baseline.Value,0))
)
替代方案可能是使用下面的自定义代码
Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
Return Nothing
Else
Return Dividend/Divisor
End If
End Function
然后你可以写下你的表达式:
=Code.Divider(
Sum(IIF(Fields!Category.Value = "Resources Capital",Fields!test.Value,0)),
Sum(IIF(Fields!Category.Value = "Resources Capital",Fields!Baseline.Value,0))
)