SSRS divide by zero error

  • Hi All.

    Hope your well. I am working on a report and seem to get a #error. Seems like it is a divide by zero error but I can not work out a solution. The expression Im using:

    =(Sum(Fields!Line_Sell.Value) - Sum(Fields!Line_Cost.Value)) / Sum(Fields!Line_Sell.Value)

    basically it is working out the total. (sell - cost) / sell = total.

    I am relatively new to RS but have tried ISNULL( ) but with no success.

    I have since tried =iif but no success to:

    =iif(Sum(Fields!Line_Sell.Value)= 0,0,Sum(Fields!Line_Sell.Value) - Sum(Fields!Line_Cost.Value) / iif(Sum(Fields!Line_Sell.Value)=0,1,Sum(Fields!Line_Sell.Value))

    Any help, I would be greatful.

    Thanks

    Steven

  • I use this embedded code in all my reports

    Public Function DivideBy(ByVal Exp1, ByVal Exp2)

    If Microsoft.VisualBasic.IsNumeric(Exp1) And Microsoft.VisualBasic.IsNumeric(Exp2) Then

    If Exp2 = 0 Then

    DivideBy = 0

    Else: DivideBy = Exp1/Exp2

    End If

    Else

    DivideBy = "N/A"

    End If

    End Function

    You call it in an expression like Code!DivideBy(Value for numerator, value for denominator) If you divide by zero it returns a zero, if one of your numbers is not really a number it will return N/A

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

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