Thursday, April 5, 2012

SSRS - CalcPercentage

This function may help if you want to display calculated percentages.  It has a parameter to multiply the total by another number. It is configured to return a large negative number on error so that it would show up as an obvious as a bad number on the report.

Public Shared Function CalcPercentage(
ByVal Numerator as double
, ByVal Denominator as double
, ByVal MultiplyBy as Double) As Double

on error goto ProcError

Dim dblRetval as Double

dblRetval = 0.00

If Not String.IsNullOrEmpty( Denominator.ToString() )
   If Denominator > 0 Then
      dblRetval = (Numerator / Denominator) * MultiplyBy
   End If
End If

Return dblRetval

ProcError:

 Return -99999999

End Function

No comments:

Post a Comment