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

Percent of Sum with a Top N report

Status
Not open for further replies.

omacron

Technical User
Feb 5, 2002
149
Doing a top N report and need to show a percentage of total, but only of the feilds being displayed. Here is my data:

Item Qty_Sold
X1000 10
X2000 1
X3000 12
X4000 5
X5000 8

Top report: N = 3

What I want to display


Item Qty_Sold Percentage of Total
X3000 12 40%
X1000 10 33.3%
X5000 8 26.7%

Total: 30

Now I know how to do the Total Qty_Sold with this forumal:

whileprintingrecords;
numbervar qtysoldN;

if groupnumber <= {?N} then
qtysoldN := qtysoldN + Sum ({Qyt_Sold}) else
qtysoldN := qtysoldN;


If I use the built in function PercentOfSum it would use the total for all the items. Therefore instead of using 30 as the total it would use 36. This would screw up the Percentages. How can i do this?
 
just add a formula like this:

whileprintingrecords;
numbervar qtysoldN;

if groupnumber <= {?N} then
qtysoldN := qtysoldN + Average ({Qyt_Sold}) else
qtysoldN := qtysoldN;
 
I would do it like this. Create two formulas:

//{@accum} to be placed in the group header section:
whileprintingrecords;
shared numbervar qtysoldN;

if groupnumber <= {?N} then
qtysoldN := qtysoldN + Sum ({Qyt_Sold},{table.item});

//{@display} to be placed in the report footer section:
whileprintingrecords;
shared numbervar qtysoldN;

Then save your report under a different name--add "-subreport" to the title, for example. Then open the original report and insert the newly saved report as a subreport to be placed in the report header. In the subreport, suppress every section so that it is blank in the main report header. Eliminate the borders as well.

Then in the main report create a formula {@PercentofTotal}:

whileprintingrecords;
shared numbervar qtysoldN;

Sum ({Qyt_Sold},{table.item}) % qtysoldN

Place this in the group header section and format it as a percent by clicking on the percent icon in the toolbar.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top