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

Dividing 2 subtotals

Status
Not open for further replies.

Dukester0122

IS-IT--Management
Mar 18, 2003
587
0
0
US
I'm trying to divide 2 subtotals and when I ran the report it gave me the Division by zero message. Here's the formula for the 2 subtotals:

Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})
 
Try:

if Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}) <> 0 then
Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})
else
0

-k
 
Same result. I still get the Division by zero message.
 
Maybe there are nulls present. Under the file menu, select options, and on the reporting tab, make sure that &quot;convert null field values to default&quot; is checked.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
then give us the whole formula....not just this snippet....the problem lies elsewhere if the above proposed solutions don't work

Jim Broadbent
 
The whole formula is what synapsevampire suggested. Seek and you will find!!!

Here it is:
if Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}) <> 0 then
Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})
else
0
 
Hi all,

I just tried dividing 0/0 on both Microsoft's calculator and in SQL Query Analyzer and each gave me exciting errors, so perhaps Crystal is also discouraging this. Thus you would have to check both:

if (Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}) <> 0 and Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) <>0) then
Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})
else
0


Just a thought!

Kristen
 
There is a CD Kbase article you may want to look at --


You might also try this (not at a machine to test this right now)

if Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}) = 0 then 0
else
Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})

Also, try adding the &quot;While Printing Records&quot; to the formula so it only gets processed when the report is being printed.

Sounds like the formula is being run before there is any value in the sum(s).


Cheers,

SurfingGecko
Home of Crystal Ease
 
For the heck of it....have the formula just print the 2 sums to see what is going on

do this....rem out the formula first then add the last line

// if Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}) <> 0 then
// Sum ({IV30300.EXTDCOST}, {IV30300.ITEMNMBR}) / Sum
// ({IV30300.TRXQTY}, {IV30300.ITEMNMBR})
// else
// 0


totext(Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}),0) +
&quot;.....&quot; +
totext(Sum ({IV30300.TRXQTY}, {IV30300.ITEMNMBR}),0);

this will let you know what is going on....


Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top