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!

calculating totals over subreports

Status
Not open for further replies.

JeroenBoon

Technical User
Aug 15, 2002
106
NL
Hello,

what is the easiest way to calculate totals over fields in subreports and use the calculated totals in the mainreport.

Jeroen Boon.
 
Your question is a good one. I will assume that you are asking how to take a total from the sub-report and use that total in the main report. I will also assume that it is a linked report and that using the built in linking parameters and other selection criteria you have added, that the sub-report has just the records you need. I will assume that you are creating grand totals in the sub-report.

1) Create a formula in the sub-report with the following expression:

whileprintingrecords;
shared numbervar sub1 := sum({table.field});
sub1

2) place this in the group footer of the sub-report.

3) Return to the main report and place the sub-report above the point that you need the value. For example, if you need the value in the group footer of the main report, place the sub-report in the group header, or in a sub-section above the section where you need it.

4) in the main report create a formula with the following expression:

whileprintingdata;
shared numbervar sub1;
sub1

or you can just use the same expression as part of the formula you need.

I hope this helps. Howard Hammerman,
Crystal Reports training, consulting, books, training material,support. HammerLauch program runs reports without Crystal
howard@hammerman.com
800-783-2269
 
Hammerman,

almost good enough, except for the following:
-main report grouped on intemnumber.
-subreport retrieves the orderlines for this itemnumber and prints them.

The shared-numbervar-thing (total amount of the article in orderlines)works, but when there are no orderlines and the subreport is empty, the numbervar is the same as in the last groupfooter where the subreport wasn't empty.

Second: i also includes a subreport for the purchase-orderlines. With an second shared numbervar (total amount in purchaseorder) i print the amount in purchaseorder in the mainreport. Same problem with the empty subreports.

And last: how do i ad the two shared numbervar's in the mainreport together?

Jeroen Boon.
 
Hammerman!!

sorry for the post i sent a couple of minutes ago, i solved the problem:
- a reset numbervar in the header to solve the problem that in case of an empty subreport the numbervar of the last not-empty subreport is repeated
- and adding the two just by making a calculated field with numbervar1+numbervar2. (duh)
Must be the fact that it's friday i didn't think clearly!

Jeroen Boon.
 
Good work! Have a great weekend. Howard Hammerman,
Crystal Reports training, consulting, books, training material,support. HammerLauch program runs reports without Crystal
howard@hammerman.com
800-783-2269
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top