Print Page | Close Window

Summing over subreports

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=13082
Printed Date: 17 May 2024 at 11:44pm


Topic: Summing over subreports
Posted By: Keikoku
Subject: Summing over subreports
Date Posted: 02 May 2011 at 8:39am
I have a report with 3 subreports.

Each subreport reports on separate sets of values and then sums them up and prints out a total.

I want to display a sum of these three totals.
Is this possible?



Replies:
Posted By: lockwelle
Date Posted: 03 May 2011 at 3:24am
use shared variables in the subreport and then the main report can access the shared variables and display the sum of them.
 
Each report would set 1 shared variable that represents it's total(or at least the total you want to sum) in a formula. The main report would access the 3 shared variables in a formula to sum/display them.
 
See CR help for more information on Shared Variables or Variable Declarations if you are not familar with the different variable types.
 
HTH


Posted By: JFinzel
Date Posted: 28 Jul 2011 at 6:16am
Can I ask a follow-up question very related to this?

What if your subreport runs 20 times, each for a different person (report is grouped by person), and you want a grand total of those subreports?  I have this situation in running a donation report for a group of twenty.

I have actually five subreports, with all the totals from those summed in the mainreport.  I was able to get these totals with shared variable, but it resets with each group.

My problem is: I want a grand total for all twenty of these people in each category (each subreport) at the report footer.

I see no way to do a running total of these subreport values.  It resets with each new person.

Much thanks for any help.  You all have been very helpful so far with the questions I have asked.


Posted By: lockwelle
Date Posted: 28 Jul 2011 at 10:39am
create another shared variable, a grandTotal and increment that each time you display the group total.  This way, even though the group is set to 0, there is no reset on the GrandTotal and you can use it where ever you wish
 
HTH


Posted By: JFinzel
Date Posted: 28 Jul 2011 at 11:58am
Do you mean to create another shared variable from within each subreport?  Or do you mean create a shared variable from within the main report?

Also, sorry but I don't quite know what you mean by incrementing it each time I display the group total.  Currently the group total is a sum of shared variables, each of which looks something like this:

whileprintingrecords;
shared currencyVar GuestGifts;
GuestGifts

These are in the section below the subreports, and I made a formula simply adding them together for a grand total.

Thank you much for your help.


Posted By: lockwelle
Date Posted: 29 Jul 2011 at 3:11am
I would place the new shared variable in the main report, since that is where you need to track/report on the sum of the subreports.
 
Since the totals for the subreports reset every time the subreport is run, you want to capture and persist that result. So if you have a formula that sums all the shared variables together to be displayed, something like:
shared numbervar x;
shared numbervar y;
shared numbervar z;
x+y+z
 
I would change it to something like:
shared numbervar x;
shared numbervar y;
shared numbervar z;
shared numbervar GrandTotal;
local numbervar a;
a:=x+y+z;
GrandTotal := GrandTotal + a;
a
 
HTH


Posted By: JFinzel
Date Posted: 29 Jul 2011 at 5:06am
Thank you again for the reply.  I tried exactly what you wrote here and the report footer is still showing only the total of the last group, not all groups.  Here is what I did:

First, the subreports are in group footer #1b.  The shared variables from them are in group footer #1c.  I used these shared variables (is that right?) to make the following formula parallel to yours:

whileprintingrecords;
shared currencyvar Gifts;
shared currencyvar GuestGifts;
shared currencyvar SoftCreditGifts;
shared currencyvar BrokerGifts;
Gifts+GuestGifts+SoftCreditGifts+BrokerGifts

I put this formula in group footer #1c with the rest.

NOW, I put this formula in Report Footer:

whileprintingrecords;
shared currencyvar Gifts;
shared currencyvar GuestGifts;
shared currencyvar SoftCreditGifts;
shared currencyvar BrokerGifts;
shared currencyvar GrTotal;
local currencyvar a;
a:=Gifts+GuestGifts+SoftCreditGifts+BrokerGifts;
GrTotal := GrTotal + a;
a

Again, it still only gives me the total of the last group, not all groups, in report footer.  Thank you much for your help.


Posted By: lockwelle
Date Posted: 29 Jul 2011 at 6:58am
where you want to see the GrandTotal you will need to write a formula to display it, like:
 
shared currencyvar GrTotal;
GrTotal
 
you will probably increment it when you display the totals for the sub, and then display it at the end of the report.
 
HTH


Posted By: JFinzel
Date Posted: 29 Jul 2011 at 9:02am
Lockwelle-

Thank you immensely.  This worked.  I put both of those first shared var formulas on the same footer #1c, then I put:

shared currencyvar GrTotal;
GrTotal

on the report footer.  This gave me my grand total!  Thank you.




Print Page | Close Window