Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by Zero Error

Status
Not open for further replies.

wanzek1

Technical User
Jun 13, 2012
79
US
I keep getting a division by zero error...

if Sum ({JCCD.ActualHours}, {@PhasePart1})= 0 then 0
else
if (Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint} = 0)
then 99999
else (Sum ({JCCD.ActualHours}, {@PhasePart1})/(Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint}))

I don't know if I am missing something in my formula but I keep get a division by zero error.

Any help would be appreciated!
 
If {@ToDate+-SubPhasePrint} is returning a null, then Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint} will return null, NOT 0, so you're not trapping for that. You have two options:

1. In the top of the formula editor change "exceptions for nulls" to "defaults value for nulls".

2. Check for null in your formula. Something like this:

if Sum ({JCCD.ActualHours}, {@PhasePart1})= 0 then 0
else
if IsNull({@ToDate+-SubPhasePrint}) or (Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint} = 0)
then 99999
else (Sum ({JCCD.ActualHours}, {@PhasePart1})/(Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint}))

Note that the check for null MUST come BEFORE the check for a value - that's the way that nulls work.

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
 
I changed the top of the formula editor change "exceptions for nulls" to "defaults value for nulls".

I also changed the formula to:

if Sum ({JCCD.ActualHours}, {@PhasePart1})= 0 then 0
else
if IsNull({@ToDate+-SubPhasePrint}) or (Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint} = 0)
then 99999
else (Sum ({JCCD.ActualHours}, {@PhasePart1})/(Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint}))

I am still getting the same error.
 
For debugging, I would break this down into a couple of formulas and check what the values are in each section where you would put the original formula (you can either remove the original formula from the report or comment out the "else" line with a "//" comment delimiter so that you don't get the error for now.)

I would put the following on the report to check the values:

{@ToDate+-SubPhasePrint}
(Sum ({JCCD.ActualHours}, {@PhasePart1})
(Sum ({JCCD.ActualHours}, {@PhasePart1})+{@ToDate+-SubPhasePrint}

At some point in the report you'll see a 0 value where you don't expect it. This will give you information about how to handle the error.

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
 
Thanks for all your help! I think the error is gone now :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top