1

我的 IIF 语句出错,我需要检查 2 个字段是否不为零,这样它就不会给出除以零的错误,请有人帮助我:

=iif(isnumeric(sum(Fields!Month13.Value, "SKU")) and 
     isnumeric(sum(Fields!Month1.Value, "SKU")),
(sum(Fields!Month13.Value, "SKU") - sum(Fields!Month1.Value, "SKU")) / 
sum(Fields!Month1.Value, "SKU"),
0)
4

3 回答 3

1

这与 SSRS 如何评估 Iif 语句有关。为避免错误,您必须使用两个 Iif 语句

=
IIF(Sum(Fields!Month1.Value)=0,0,Sum(Fields!Month13.Value) -Sum(Fields!Month1.Value))
/
IIF(Sum(Fields!Month1.Value)=0,1,Sum(Fields!Month1.Value))

另一种选择是使用自定义代码函数,如下所示

Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
  Return 0
Else
  Return Dividend/Divisor
End If
End Function 

于 2017-01-18T09:02:26.383 回答
0

根据你想如何处理这个你可以做

=iif(isnumeric(sum(Fields!Month13.Value, "SKU")) and 
 isnumeric(sum(Fields!Month1.Value, "SKU")) and
 sum(Fields!Month1.Value, "SKU") > 0,
(sum(Fields!Month13.Value, "SKU") - sum(Fields!Month1.Value, "SKU")) / 
sum(Fields!Month1.Value, "SKU"),
0)

或在 IIF 语句中放置另一个 IIF 语句以检查 month1 的总和是否大于 0,否则为 1。

=iif(isnumeric(sum(Fields!Month13.Value, "SKU")) and 
 isnumeric(sum(Fields!Month1.Value, "SKU")),
(sum(Fields!Month13.Value, "SKU") - sum(Fields!Month1.Value, "SKU")) / 
iif(sum(Fields!Month1.Value, "SKU") > 0, sum(Fields!Month1.Value, "SKU"), 1)
0)
于 2013-11-08T12:52:15.977 回答
-1

好的,所以最后我使用了这个:

=IIf(Sum(Fields!Month13.Value) = 0, -1, 
iif(Sum(Fields!Month1.Value) = 0,1,
(Sum(Fields!Month13.Value) - Sum(Fields!Month1.Value)) / 
IIf(Sum(Fields!Month1.Value) = 0, 1, Sum(Fields!Month1.Value))))
于 2013-11-08T13:26:22.130 回答