0

Hopefully I might have the easiest question to answer but so far I couldn't figure it out. I have a RDLC report with following expression.

    =Iif(Sum(Fields!OriginalTotal.Value) = 0, 0, (Sum(Fields!WorkingTotal.Value) - Sum(Fields!OriginalTotal.Value))/Sum(Fields!OriginalTotal.Value)) 

Please note that this field on the report is formatted as percentage with two decimal places.

Problem is whenever the Sum(Fields!OriginalTotal.Value) = 0 condition is true, field prints as "#Error" on the report.

What am I doing wrong here?

Thanks in Advance!

ecasper
  • 489
  • 1
  • 10
  • 30

2 Answers2

1

There is a well known problem that ssrs calculates both expressions of "iif". That's why you get Error when trying to divide on 0.

Have a look at the following links:

Community
  • 1
  • 1
SuperCuke
  • 168
  • 6
0

Instead of Writing expression in SSRS. We can add a function to your report code that handles the divide by zero condition, this makes it a bit easier to implement in multiple cells(code re-usability),

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

We can call this code in a cell as follows,

=Code.Divider(Fields!Dividend.Value, Fields!Divisor.Value)

Thanks
Venky