locked
divide by zero # Error RRS feed

  • Question

  • In sql server reporting services I am getting a #Error

    Here is what my code looks like

    =iif(Fields!TOTAL_EMAIL_I4C.Value = 0 or Fields!TOTAL_ETLK_I4C.Value = 0, 0, Fields!TOTAL_ETLK_I4C.Value/Fields!TOTAL_EMAIL_I4C.Value)
    Tuesday, April 14, 2009 5:28 PM

Answers

  • IIF is always evaluating all arguments before it executes. It means that you'll get "division by zero" in your expression in this part - (Fields!TOTAL_ETLK_I4C.Value/Fields!TOTAL_EMAIL_I4C.Value) if Fields!TOTAL_EMAIL_I4C.Value equal 0.

    To avoid this problem you should use a pattern like this:
    =iif(B=0, 0, A / iif(B=0, 1, B))

    In your case:
    =iif(Fields!TOTAL_EMAIL_I4C.Value = 0 , 0, Fields!TOTAL_ETLK_I4C.Value/IIF(Fields!TOTAL_EMAIL_I4C.Value=0, 1, Fields!TOTAL_EMAIL_I4C.Value))
    • Marked as answer by jaguar829 Wednesday, April 15, 2009 1:46 PM
    Tuesday, April 14, 2009 8:03 PM
    Answerer

All replies

  • Try this
    =iif(Fields!TOTAL_EMAIL_I4C.Value = 0 , 0,iif( Fields!TOTAL_ETLK_I4C.Value = 0, 0, Fields!TOTAL_ETLK_I4C.Value/Fields!TOTAL_EMAIL_I4C.Value))
    ~~ Mark it as Answer if you find it correct~~
    Tuesday, April 14, 2009 5:37 PM
  • Hello,

    Try this

    =iif(VAL(Fields!TOTAL_EMAIL_I4C.Value) = 0 or VAL(Fields!TOTAL_ETLK_I4C.Value) = 0, 0, VAL(Fields!TOTAL_ETLK_I4C.Value)/VAL(Fields!TOTAL_EMAIL_I4C.Value))

    Hope helpful...


    Pavan http://www.ggktech.com
    Tuesday, April 14, 2009 5:41 PM
  • IIF is always evaluating all arguments before it executes. It means that you'll get "division by zero" in your expression in this part - (Fields!TOTAL_ETLK_I4C.Value/Fields!TOTAL_EMAIL_I4C.Value) if Fields!TOTAL_EMAIL_I4C.Value equal 0.

    To avoid this problem you should use a pattern like this:
    =iif(B=0, 0, A / iif(B=0, 1, B))

    In your case:
    =iif(Fields!TOTAL_EMAIL_I4C.Value = 0 , 0, Fields!TOTAL_ETLK_I4C.Value/IIF(Fields!TOTAL_EMAIL_I4C.Value=0, 1, Fields!TOTAL_EMAIL_I4C.Value))
    • Marked as answer by jaguar829 Wednesday, April 15, 2009 1:46 PM
    Tuesday, April 14, 2009 8:03 PM
    Answerer
  • I've found one more way to resolve such problem.

    You should create  the user function in the Reporting Services with such commands:

    Public Function SafeDivide(Numerator as Double, Denominator as Double) as Double
    If Denominator = 0 then return 0
    Return (Numerator / Denominator)
    End Function

    Function in use(example):
    =100 * Code.SafeDivide(reportitems!textbox141.value,reportitems!textbox43.value)
    • Proposed as answer by s-stude Thursday, April 23, 2009 8:54 AM
    Thursday, April 23, 2009 8:47 AM