Handle Divide by Zero in SQL Reporting Services

  • Clayton Groom

    SSC-Addicted

    Points: 410

    Comments posted to this topic are about the item Handle Divide by Zero in SQL Reporting Services

    Kindest Regards,

    Clayton

  • missmissalissa

    SSC Journeyman

    Points: 77

    I'm new to SSRS and I'm having trouble understanding how to use this script. Can you please assist?

    I've entered the following in the report perameters - code window.

    Public Function CalcRatio(ByVal Numerator As Object, ByVal Denominator As object, ByVal DivZeroDefault As Object) As Object

    If Denominator <> 0 Then

    Return Numerator/Denominator

    Else

    Return DivZeroDefault

    End If

    End Function

    I then entered the following in the expression of the textbox.

    =code.CalcRatio((sum(Fields!total.Value)+(Fields!Adjustment.Value))/Fields!Goal.Value, 0)

    but I get the following error.

    The Value expression for the textbox ‘textbox28’ contains an error: [BC30455] Argument not specified for parameter 'DivZeroDefault' of 'Public Function CalcRatio(Numerator As Object, Denominator As Object, DivZeroDefault As Object) As Object'.

    What am I doing wrong?

    Thanks in advance for any help you may be able to provide.

    Regards,

    Missa

  • giosalma

    Valued Member

    Points: 67

    Thank you, Thank you, Thank you, Thank you, Thank you, Thank you.

  • pnelson 10021

    SSC Enthusiast

    Points: 116

    How can I apply the custom code to this following expression?

    =((Sum(Fields!test1.Value) / Sum(Fields!test9.Value) * 10 + Sum(Fields!test2.Value) / Sum(Fields!test9.Value) * 10 + Sum(Fields!test3.Value) / Sum(Fields!test9.Value) * 10 + Sum(Fields!test4.Value) / Sum(Fields!test9.Value) * 10) – (Sum(Fields!test5.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test6.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test7.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test8.Value) / Sum(Fields!test10.Value) * 10)) / (Sum(Fields!test5.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test6.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test7.Value) / Sum(Fields!test10.Value) * 10 + Sum(Fields!test8.Value) / Sum(Fields!test10.Value) * 10)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply