Wednesday, May 16, 2012

Custom Code for Dividing Numbers in SSRS

Hi,

Use this custom code when you perform division of 2 numbers. This is essential as when you to try to divide 2 numbers & if the denominator is 0, during run-time the textbox will show error. Below is the code that you can use for eliminating this :

Custom Code:
Public Function SafeDivide(ByVal Numerator, ByVal Denominator)
If Microsoft.VisualBasic.IsNumeric(Numerator) And Microsoft.VisualBasic.IsNumeric(Denominator) Then
If Denominator = 0 Then
  SafeDivide = 0
Else: SafeDivide = Numerator/Denominator
End If
Else
SafeDivide = "N/A"
End If
End Function








                                                                                                                                                                              
write the code function Name in required field like
 =Code.SafeDivide(Fields!Name1.Value,Fields!Name2.Value)
Now if you see the result, You will get exact result. Problem Solved!!!!!!!!

No comments:

Post a Comment