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.
