on 07-02-2007 9:28 PM
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) ) )
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.