SSRS Expression Divide by Zero Error

后端 未结 3 1926
不知归路
不知归路 2020-11-27 05:46

I have a tablix box that has a division expression. When dividing by zero or nulls I get #Error displayed in my report. I tried to create an IIF st

3条回答
  •  野性不改
    2020-11-27 06:30

    I suspect you're running into the issue where SSRS doesn't actually short circuit an IIF statement; even though you're checking for 0, you're still going to hit a divide by zero error.

    Try something like:

    =IIf(Sum(Fields!PY_Dollars.Value) = 0, 0, Sum(Fields!CY_Dollars.Value) - Sum(Fields!PY_Dollars.Value))
      / IIf(Sum(Fields!PY_Dollars.Value) = 0, 1, Sum(Fields!PY_Dollars.Value))
    

    Using two IIf statements means you avoid the error by using the equation 0/1 when Sum(Fields!PY_Dollars.Value) = 0, thus just returning 0.

    Also note that the above expression is checking Sum(Fields!PY_Dollars.Value) = 0, but yours is checking Sum(Fields!CY_Dollars.Value) = 0 - the denominator needs the zero check here.

提交回复
热议问题