Menu Close

Divide by Zero Error

In SSRS when you try to divide by zero you end up with a #Error output message. To avoid this you can use some of the methods below.

Method 1:
1. Hit the “Design” tab of the report.
2. Go to “Report” then from the drop down select “Report Properties”

3. Click on “Code” and paste the following:

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

4. Use the following expression:

=Code.Divider(Fields!FieldA.Value, Fields!FieldB.Value)

Method 2:
Use the following expression:

=IIf(Fields!SomeField.Value = 0, 0, Fields!SomeOtherField.Value / IIf(Fields!SomeField.Value = 0, 1, Fields!SomeField.Value))

Method 3:
Use the following expression:

=IIF
(
Fields!SomeField.Value = 0
, 0
, Fields!SomeOtherField.Value * Fields!SomeField.Value ^ -1
)