SSRS Divide By Zero Error

An easy clean way to prevent a divide by zero error is using the report code area.

In the Menu; got to Report > Report Properties > Code and paste the code bellow

Public Function Quotient(ByVal numerator As Decimal, denominator As Decimal) As Decimal
        If denominator = 0 Then
            Return 0
        Else
            Return numerator / denominator
        End If
    End Function

To call the function go to the the Textbox expresion and type:

=Code.Quotient(SUM(fields!FieldName.Value),SUM(Fields!FieldName2.Value))

 in this case I am putting the formula at the Group level so I am using sum. Otherwise it would be:

=Code.Quotient(fields!FieldName.Value,Fields!FieldName2.Value)

Related Posts

Comments are closed.