Call us: 505-NEXTPRO (505-639-8776)

Reports · Tips

Dividing by Zero in ProLaw® Reports

October 26, 2024

It may be necessary to use Visual Basic code in your reports to accomplish tasks that the default report functionality can't handle. A very common example is division — SSRS may error when dividing by 0.

The Solution: A VB Function

Right-click on the background of the report (not the body), select Report Properties, then Code. Paste this into the code window:

Public Shared Function DividebyZero(ByVal Actual As Decimal, ByVal Total As Decimal) As Decimal
  If Total = 0 Then
    Return 0
  End If
  Return (Actual / Total)
End Function

Using the Function in an Expression

After adding the function, write your expression like this:

=Code.DividebyZero(Fields!FirstField.Value, Fields!LYTDBalance.Value)

This safely returns 0 instead of an error when the denominator is zero.

Have a ProLaw® question?

Our team is here to help with anything ProLaw® — from quick questions to complex implementations.

Get in touch