IIF声明与运营商 - SSRS

时间:2013-11-08 12:44:51

标签: reporting-services iif

我的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)

3 个答案:

答案 0 :(得分: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 

答案 1 :(得分: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)

答案 2 :(得分:-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))))