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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by 0 error in formula 1

Status
Not open for further replies.

grpeachtree

Technical User
Sep 5, 2012
7
I am using Peachtree Premium 2012, Crystal Reports 2008, pervasive sql is the database engine.

I am trying to create a formula to divide one field by another and eliminate the risk of dividing by 0.
My formula is:

(If {@Total Testers} <> 0 or if {@Total Sales} <> 0) then ({@Total Testers}/{@Total Sales} * 100) else 0

I have also tried:

(If {@Total Testers } <> 0 and if {@Total Sales} <> 0) then ({@Total Testers}/{@Total Sales} * 100) else 0

The result is the same: an error message displays the keyword "Then" is missing
After I click OK the cursor sits on the right parenthesis of "or if {@Total Sales} <> 0)"

Can someone help me with the correct syntax for the formula?
 
if {@Total Sales} > 0 then {@Total Testers}/{@Total Sales} else 0

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 
Thank you, Cospringsguy.

I do need to perform the calculation even when the amount is negative, so my formula ended up as:

If Sum ({@Total Testers}, {JrnlHdr.EmpRecordNumber}) = 0 then 0
else (Sum ({@Total Testers}, {JrnlHdr.EmpRecordNumber})/Sum ({@Total Sales}, {JrnlHdr.EmpRecordNumber}) * 100)
 
i think this --

If ({@Total Testers } <> 0 and {@Total Sales} <> 0) then ({@Total Testers}/{@Total Sales} * 100) else 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top