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!

Crosstab Divide by Zero / Margin % Issue

Status
Not open for further replies.

Polarican0115

Technical User
Jan 11, 2013
18
US
CR2011
I created a Crosstab report By Specialty Dept that displays Sales, Gross Profit and Gross Profit % by Order Type (Stock Sales/Direct Sales).

The Problem I am encountering is when the Sum of Specialty Dept = $0.00 but the Gross Profit Margin has a value, the Margin % does not get calculated correctly

To get Sales, Margin and Percentage in the Crosstab, I created the following:

Sales (Suppress formula)
whileprintingrecords;
numbervar tot := currentfieldvalue;
false

Gross Profit $ (Suppress Formula)
whileprintingrecords;
numbervar coded := currentfieldvalue;
false

Gross Marg % (Display String formula)
whileprintingrecords;
numbervar tot;
numbervar coded;
if tot <> 0 then
totext(coded%tot,2)+"%" //2 for two decimals
else "0.00%"//Added this because if tot = 0 it will be suppressed

This is what displays on the Crosstab report:

Divideby0Help_zpsa6ce83a1.jpg.html
Divideby0Help_zpsa6ce83a1.jpg
[/URL]]

If I do the following, (Comment out the if tot <> 0) I get the Divide by zero message:

whileprintingrecords;
numbervar tot;
numbervar coded;
//if tot <> 0 then
totext(coded%tot,2)+"%" //2 for two decimals
//else "0.00%"

Divideby0Help1_zps4276f6e7.jpg.html
Divideby0Help1_zps4276f6e7.jpg
[/URL]]

Any help/suggestions would be greatly appreciated.
 
I ended up using a not so sophisticated work around, but it worked.

When the Sum of Sales = 0, I figured I might as well just use the Margin$ value and add the % sign. Mathematically it works out the same anyway.

I made this simple adjustment:

whileprintingrecords;
numbervar tot;
numbervar coded;

if tot = 0 then
totext(coded,2)+"%" else
if tot <> 0 then
totext(coded%tot,2)+"%" //2 for two decimals
else "0.00%"

If anyone knows of a better way (or the correct way this should have been handled) I would definitely appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top