Solved

Division by Zero

Posted on 2008-06-13
6
343 Views
Last Modified: 2012-08-13
Hi there,

I am getting a division by zero error again. I had the similar issue in March and I posted a question regarding it (please see post # 23209772). I applied the solution recommended and the report has been working fine until this month where I am getting the same error again. The formula that I am using is below:

If (Sum ({@Oct 07}, {@Item / Variant})) +  (Sum ({@Nov 07}, {@Item / Variant})) + (Sum ({@Dec 07}, {@Item / Variant}))  + (Sum ({@Jan 08}, {@Item / Variant})) + (Sum ({@Feb 08}, {@Item / Variant})) + (Sum ({@Mar 08}, {@Item / Variant})) + (Sum ({@Apr 08}, {@Item / Variant})) + (Sum ({@May 08}, {@Item / Variant}))= 0 and (Sum ({@Oct Plan 07}, {@Item / Variant})) + (Sum ({@Nov Plan 07}, {@Item / Variant})) + (Sum ({@Dec Plan 07}, {@Item / Variant})) + (Sum ({@Jan Plan 08}, {@Item / Variant})) + (Sum ({@Feb Plan 08}, {@Item / Variant})) + (Sum ({@Mar Plan 08}, {@Item / Variant})) + (Sum ({@Apr Plan 08}, {@Item / Variant})) + (Sum ({@May Plan 08}, {@Item / Variant}))> 0
then "FES"
else if (Sum ({@Oct 07}, {@Item / Variant})) + (Sum ({@Nov 07}, {@Item / Variant})) + (Sum ({@Dec 07}, {@Item / Variant})) + (Sum ({@Jan 08}, {@Item / Variant})) + (Sum ({@Feb 08}, {@Item / Variant})) + (Sum ({@Mar 08}, {@Item / Variant})) + (Sum ({@Apr 08}, {@Item / Variant}))+ (Sum ({@May 08}, {@Item / Variant})) >0 and (Sum ({@Oct Plan 07}, {@Item / Variant})) + (Sum ({@Nov Plan 07}, {@Item / Variant})) + (Sum ({@Dec Plan 07}, {@Item / Variant})) + (Sum ({@Jan Plan 08}, {@Item / Variant})) + (Sum ({@Feb Plan 08}, {@Item / Variant}))+ (Sum ({@Mar Plan 08}, {@Item / Variant})) + (Sum ({@Apr Plan 08}, {@Item / Variant}))+(Sum ({@May Plan 08}, {@Item / Variant})) = 0
then "SEF"
else if (Sum ({@Oct 07}, {@Item / Variant})) + (Sum ({@Nov 07}, {@Item / Variant})) + (Sum ({@Dec 07}, {@Item / Variant})) + (Sum ({@Jan 08}, {@Item / Variant}))+ (Sum ({@Feb 08}, {@Item / Variant})) + (Sum ({@Mar 08}, {@Item / Variant})) + (Sum ({@Apr 08}, {@Item / Variant})) + (Sum ({@May 08}, {@Item / Variant})) = 0 and (Sum ({@Oct Plan 07}, {@Item / Variant})) + (Sum ({@Nov Plan 07}, {@Item / Variant})) + (Sum ({@Dec Plan 07}, {@Item / Variant})) + (Sum ({@Jan Plan 08}, {@Item / Variant})) + (Sum ({@Feb Plan 08}, {@Item / Variant})) + (Sum ({@Mar Plan 08}, {@Item / Variant}))+ (Sum ({@Apr Plan 08}, {@Item / Variant}))+(Sum ({@May Plan 08}, {@Item / Variant}))= 0 then '1'
else
CStr (((Sum ({@Oct 07}, {@Item / Variant})) + (Sum ({@Nov 07}, {@Item / Variant})) +(Sum ({@Dec 07}, {@Item / Variant})) + (Sum ({@Jan 08}, {@Item / Variant}))+ (Sum ({@Feb 08}, {@Item / Variant}))+ (Sum ({@Mar 08}, {@Item / Variant}))+ (Sum ({@Apr 08}, {@Item / Variant}))+ (Sum ({@May 08}, {@Item / Variant})) )/((Sum ({@Oct Plan 07}, {@Item / Variant})) + (Sum ({@Nov Plan 07}, {@Item / Variant})) + (Sum ({@Dec Plan 07}, {@Item / Variant}))+ (Sum ({@Jan Plan 08}, {@Item / Variant}))+ (Sum ({@Feb Plan 08}, {@Item / Variant}))+ (Sum ({@Mar Plan 08}, {@Item / Variant}))+ (Sum ({@Apr Plan 08}, {@Item / Variant}))+(Sum ({@May Plan 08}, {@Item / Variant})))  * 100)


Thanks




0
Comment
Question by:sgaurav7
  • 2
  • 2
  • 2
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 21782121
What is @MONTH XX, and @ITEM/VARIANT code?

mlmcc
0
 

Author Comment

by:sgaurav7
ID: 21782251
@MONTH XX is the formula to get the invoiced sales for the current fiscal year

For example, the formula for April 2008 ({Apr 08}) comes from:

if {@Year Selection = '2008'
and Month ({BU_SFA_DETAIL2.invoice_dt}) = '4'
then {BU_SFA_DETAIL2.quantity}

@Item/Variant is just the concatenation of the Item_no and variant_no (Product Code and the Size)
{BU_SFA_DETAIL2.item_no} + '/' + {BU_SFA_DETAIL2.variant_no}
0
 
LVL 42

Expert Comment

by:frodoman
ID: 21782845
It looks to me like the part of your last 'else' statement below the division sign must evaluate to zero.  In other words for some value of {@Item/Variant}, the sum of all of the months is equal to zero.

If you need to be excruciatingly accurate you'll need to check this to make sure it's <> 0 before you do the calculation.  If you can tolerate a very small error then you can probably fix easier by adding 0.0000001 to the value below the division sign.  Eg:

....}))+(Sum ({@May Plan 08}, {@Item / Variant})))  * 100)

becomes

....}))+(Sum ({@May Plan 08}, {@Item / Variant})))  * 100 + 0.0000001)

This insures that the value will never be zero.  It does alter the results very slightly - if you're dealing with common scenarios it's below what you'll be rounding anyway but if you're dealing with precision that tight than you'll have to use an "if" statement.

frodoman
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 42

Accepted Solution

by:
frodoman earned 500 total points
ID: 21782858
Correction - I think I miscounted the parenthesis.  The modified value would be:

....}))+(Sum ({@May Plan 08}, {@Item / Variant})) + 0.0000001 )  * 100)


frodoman
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 21783101
Could there possibly be no data for May08?

mlmcc

0
 

Author Closing Comment

by:sgaurav7
ID: 31467034
You are genius....this worked just fine. thanks!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IF THEN Statement not working 3 44
cross tab report accumulative amount 9 51
Join issues with Crystal Report 10 69
shared number array to be used in subreport 8 22
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now