SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
Jyots
Jyots
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 69
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
Tee Time
Tee Time
Say Hey Kid
Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)Say Hey Kid (671 reputation)

Group: General Forum Members
Points: 671 Visits: 465
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)))
Jyots
Jyots
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 69
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
Daniel Bowlin
Daniel Bowlin
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4082 Visits: 2629
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search