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

Percentage of Group Totals

Status
Not open for further replies.

YANKRAY

Technical User
Nov 7, 2003
283
Crystal 10.0

I have a report that groups hours charged by:

Group 1 (Category) There are 2 categories "DI" and "ID"
Group 2 (Department)
Group 3 (Project)

Where each project is listed in Categroy DI, I want to show the percentage of the total Project Hours.

For example my current result looks like:

Project Hours
001 50
002 20
003 80
Dept 3200 150

001 30
002 10
003 50
004 20
Dept 3300 110

I need help with a formula that will give me the following result:

Project Hours % of Project total
001 50 62.5%
002 20 66.7%
003 80 61.5%
Dept 3200 150

001 30 37.5%
002 10 33.3%
003 50 38.5%
004 20 100.0%
Dept 3300 110


 
You could create a subreport that is grouped by category and project, and then link it to the main report by category and project. In the subreport, create a formula to be placed in the subreport group footer:

whileprintingrecords;
shared numbervar projtot := sum({table.hours};

Place this formula on the subreport canvas and then suppress all sections of the subreport. Place the subreport in a group header_a (Project) section, and then place your other fields in group header_b, adding the following formula:

//{@projpercent}:
whileprintingrecords;
shared numbervar projtot;

sum({table.hours},{table.project}) % projtot

-LB
 
LB -

I have created the subreport and placed it in the main formula.

The formula:

//{@projpercent}:
whileprintingrecords;
shared numbervar projtot;

is giving me a division by zero error message.

 
Then change it to:

//{@projpercent}:
whileprintingrecords;
shared numbervar projtot;

if projtot = 0 then 0 else
sum({table.hours},{table.project}) % projtot

...although it doesn't really make sense that you would have projects appearing with zero hours, does it?

-LB
 
You're right, it doesn't make sense.

What I got was a 0% for every Project so I must have placed something wrong.

On the subreport, the formula

//{@projpercent}:
whileprintingrecords;
shared numbervar projtot;

gives the total for the entire report.
 
I think you forgot to link the subreport by category and by project to the main report. Go to edit->edit subreport links->and create the links there.

You also need to have the subreport in a section above the one in which you do the percentage calculation ({@projpercent}). If you need more help with this, please explain exactly where you have located the subreport and the formula in the main report that calculates the percent.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top