none
Divided by zero error RRS feed

  • Question

  • HI ,

    Am using following expression in one of my text box. But getting error. Please do need full

    =format
    (((sum(Fields!MonthlyAmt.Value))/
                             (((sum(iif(Fields!Lsfrom.Value>Fields!ASOFDATE.Value and fields!LeaseName.Value <>"VACANT" ,nothing,Fields!Squr.Value)))
                                    -
                           (iif(sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1") is nothing,0,sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1")))))
     ),"#,0.00")

    Thanks in advance.


    bala krishna

    Thursday, March 27, 2014 3:36 PM

Answers

  • Hi bala,

    According to your description, it seems that when the denominator is equal to 0, it will throw an error message that “Attempted to divide by zero”. In this scenario, we can use custom code to prevent errors caused by dividing by zero.

    • Click Report Properties on the Report menu. Click the Code tab and enter the following code in the Custom Code box:
      Function Divide(Numerator as Decimal, Denominator as Decimal)
      If Denominator = 0 Then
      Return 0
      Else
      Return Numerator/Denominator
      End If
      End Function
    • Then, use the expression
      =Code.Divide(Fields!Field1.Value, Fields!Field2.value)
      to replace
      = Fields!Field1.Value / Fields!Field2.value


    If there are any misunderstanding, please elaborate the issue for further investigation.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    Monday, March 31, 2014 11:44 AM
    Moderator
  • =format
    (((sum(Fields!MonthlyAmt.Value))/
                             iif((((sum(iif(Fields!Lsfrom.Value>Fields!ASOFDATE.Value and fields!LeaseName.Value <>"VACANT" ,nothing,Fields!Squr.Value)))
                                    -
                           (iif(sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1") is nothing,0,sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1")))))
    =0,Nothing,(((sum(iif(Fields!Lsfrom.Value>Fields!ASOFDATE.Value and fields!LeaseName.Value <>"VACANT" ,nothing,Fields!Squr.Value)))
                                    -
                           (iif(sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1") is nothing,0,sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1"))))))
     ),"#,0.00")


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    Monday, March 31, 2014 11:54 AM

All replies

  • Hi bala,

    According to your description, it seems that when the denominator is equal to 0, it will throw an error message that “Attempted to divide by zero”. In this scenario, we can use custom code to prevent errors caused by dividing by zero.

    • Click Report Properties on the Report menu. Click the Code tab and enter the following code in the Custom Code box:
      Function Divide(Numerator as Decimal, Denominator as Decimal)
      If Denominator = 0 Then
      Return 0
      Else
      Return Numerator/Denominator
      End If
      End Function
    • Then, use the expression
      =Code.Divide(Fields!Field1.Value, Fields!Field2.value)
      to replace
      = Fields!Field1.Value / Fields!Field2.value


    If there are any misunderstanding, please elaborate the issue for further investigation.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    Monday, March 31, 2014 11:44 AM
    Moderator
  • =format
    (((sum(Fields!MonthlyAmt.Value))/
                             iif((((sum(iif(Fields!Lsfrom.Value>Fields!ASOFDATE.Value and fields!LeaseName.Value <>"VACANT" ,nothing,Fields!Squr.Value)))
                                    -
                           (iif(sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1") is nothing,0,sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1")))))
    =0,Nothing,(((sum(iif(Fields!Lsfrom.Value>Fields!ASOFDATE.Value and fields!LeaseName.Value <>"VACANT" ,nothing,Fields!Squr.Value)))
                                    -
                           (iif(sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1") is nothing,0,sum(iif(Fields!LeaseName.Value = "VACANT",Fields!Squr.Value,Nothing),"Group1"))))))
     ),"#,0.00")


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    Monday, March 31, 2014 11:54 AM