cancel
Showing results for 
Search instead for 
Did you mean: 

Division by Zero

Former Member
0 Kudos

Post Author: bkaufman

CA Forum: Formula

Can anyone tell me why I'm getting a division by zero error. I think this formula should return a 0 if either of these fields are = 0 or return a percent if they are not. Any suggestions.

IIF (Sum ({SM_Management_Info.Point End Bal}, {SM_Management_Info.Market Name})=0, 0,IIF (Sum ({SM_Management_Info.End Base Bal}, {SM_Management_Info.Market Name}) = 0, 0, Round((Sum ({SM_Management_Info.Point End Bal}, {SM_Management_Info.Market Name}) % Sum ({SM_Management_Info.End Base Bal}, {SM_Management_Info.Market Name})) - 100,1) ) )

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Post Author: qcheng

CA Forum: Formula

I copied the following statement from the Crystal Report Online Help for IFF function which may answer your question:

Every argument of the IIF function is evaluated before the result is returned. Thus, you should watch out for undesirable side effects when using IIF. For example, if falsePart results in division by zero, an error will occur, even if expression is True and so truePart is returned.

Former Member
0 Kudos

Post Author: synapsevampire

CA Forum: Formula

IIFs always make formulas more complex to understand.

Anyway, use this instead, more readable and less code:

Can anyone tell me why I'm getting a division by zero error. I think this formula should return a 0 if either of these fields are = 0 or return a percent if they are not. Any suggestions.

if Sum ({SM_Management_Info.End Base Bal}, {SM_Management_Info.Market Name}) = 0 then0elseSum ({SM_Management_Info.Point End Bal}, {SM_Management_Info.Market Name}) % Sum ({SM_Management_Info.End Base Bal}, {SM_Management_Info.Market Name})

You don't need to check both values, just the divisor.

It's just a standard divided by error common to almost every programming language.

-k