Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Summing over subreports Post Reply Post New Topic
Author Message
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Topic: Summing over subreports
    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?


Edited by Keikoku - 02 May 2011 at 8:39am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet 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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet 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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet 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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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


Edited by lockwelle - 29 Jul 2011 at 6:59am
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet 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.

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.