Custom code for division throws an #Error message for NON EXISTING record.

  • Hi,

    I get numerator from dataset and denominator from function and pass them to the custom code function which gives division result.

    Something like below code:

    =IIF(Sum(Fields!Value1.Value)<>0,Code.GetPerc(Sum(Fields! Value1.Value),(IIF(IsNothing(Code.GetValue2()),0,Code.Get_Value()))),0)

    If record for Value1 does not exist then it gives #Error else it works fine.

    How to handle non existing record in such calculation?

    Thanks,

    JM

  • I'm guessing you are seeing the division by zero error type error here?

    You may be able to modify something like this to get what you are after. Swap out the 0 for is nothing.

    =Iif(Sum(Fields!EXT_SALE_AMT.Value) = "0.00", "-100", Sum(Fields!MARGIN_DOLLARS.Value) / Iif(Sum(Fields!EXT_SALE_AMT.Value) = "0.00", "1", <<<<<<<<<<< If the value is 0 this makes it 1.

    Sum(Fields!EXT_SALE_AMT.Value)))

  • Hi,

    Thanks for your reply.

    But it’s not division by zero error. I have handled that in code as follows:

    Public Function DivisionFunction(ByVal Value_1 AS Decimal, Value_2 AS Decimal) AS Decimal

    Dim bal As Decimal

    if ((IsNothing(Value_1) Or Value_1 = 0) Or (IsNothing(Value_2) Or Value_2 = 0))

    bal=0

    else

    bal=Value_1/Value_2

    end if

    return bal

    End Function

    Here, I get an error when I divide non existing value which is value1 (numerator) / Value2 (Denominator).

    Value1 = sum of Value1 on child group (Child1, Child2,…….)

    Value2 = sum of Value2 on parent group (Parent1)

    I fetch Value2 from Custom Code function and send Value1 and Value2 for division.

    Regards,

    JM

  • I am not sure it will work with non existent values but you might want to check out the divide by zero code I posted here:

    http://www.bidn.com/blogs/Daniel/ssas/1245/divide-by-zero-tweak

    It might help.

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

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