Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Counting the Summary Results Post Reply Post New Topic
Author Message
judylynn
Newbie
Newbie
Avatar

Joined: 17 Nov 2008
Location: United States
Online Status: Offline
Posts: 22
Quote judylynn Replybullet Topic: Counting the Summary Results
     Posted: 17 Dec 2009 at 11:21am
I have a need to count up the results of a Summary, but I'm not sure how to go about it. In other words, I'd like to summarize a summary. I have three groups on the following fields: Family ID (identifies a household), Name (identifies each person in the household), and Program (identifies programs each person is enrolled in.
I have a DistinctCount summary on the Program field that displays in Group 1 (Family ID) so that it shows how many programs each household is associated with. I've been asked to come up with a report that will show how many households are associated 1 program, 2 programs, 3 programs, etc...
 
Crystal won't let me put a Summary on the results of the existing Summary. Nor will it let me group by the Summary results.
 
I have very limited experience with formulas, but I have done some simple ones. Can someone put me on the right path??
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 18 Dec 2009 at 6:06am
you can use variables in your formulas that will persist, and will allow you to create your own summaries.  Usually a formula like this will have 3 formulas (there may be more, depending on how many items you are tracking)
1 formula resets the variable: (usually in a group header)
shared numbervar aVar:=0;
 
1 formula to display: (usually in the group footer)
shared numbervar aVar
 
1 forula to increment: (usually in the detail section, though in this case if you wanted you might be able to do it in the footer using an aggregate function)
shared numbervar aVar;
aVar := aVar + {table.field};//usually there is an if statement to control incrementing.
IP IP Logged
judylynn
Newbie
Newbie
Avatar

Joined: 17 Nov 2008
Location: United States
Online Status: Offline
Posts: 22
Quote judylynn Replybullet Posted: 21 Dec 2009 at 12:12pm
I've put in the summary using variables, so it's giving me the count of programs enrolled in for each customer. Now I'm still stuck as to how to count the occurrences of each number (customers enrolled in 3 programs, in 4 programs, etc...). I still cannot put a count summary on the result.  
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Dec 2009 at 6:06am
you would need to define your categories, but I would use more variables and set them based on if statements...
 
the built in aggregates only work in a deterministic way, ie counting all occurrances in the dataset. Once you start excluding some data from the total, it is indeterminate to CR.  Why? I don't really know, I am guessing that it has to do with the multiple reads of the data that CR does and where it determines the aggregates vs formulas being applied.
 
this is just my conjecture from using CR.
 
HTH
IP IP Logged
judylynn
Newbie
Newbie
Avatar

Joined: 17 Nov 2008
Location: United States
Online Status: Offline
Posts: 22
Quote judylynn Replybullet Posted: 22 Dec 2009 at 11:00am
This is working by using the formula below, where aVar is summarizing (counting) the number of programs per customer, and Tally1, Tally2, etc... are counting the occurences of each number in the first summary.
 
 
Shared NumberVar aVar;
Shared NumberVar Tally10;
Shared NumberVar Tally9;
Shared NumberVar Tally8;
Shared NumberVar Tally7;
Shared NumberVar Tally6;
Shared NumberVar Tally5;
Shared NumberVar Tally4;
Shared NumberVar Tally3;
Shared NumberVar Tally2;
Shared NumberVar Tally1;
Shared NumberVar Tallymorethan10;
If aVar = 10 then (Tally10 := Tally10 + 1)
else if aVar = 9 then (Tally9:= Tally9 + 1)
else if aVar = 8 then (Tally8:= Tally8 + 1)
else if aVar = 7 then (Tally7:= Tally7 + 1)
else if aVar = 6 then (Tally6:= Tally6 + 1)
else if aVar = 5 then (Tally5:= Tally5 + 1)
else if aVar = 4 then (Tally4:= Tally4 + 1)
else if aVar = 3 then (Tally3:= Tally3 + 1)
else if aVar = 2 then (Tally2:= Tally2 + 1)
else if aVar = 1 then (Tally1:= Tally1 + 1)
else Tallymorethan10 := Tallymorethan10 + 1
 
My new question is- how do I get the results of each Tally variable to display? Declaring Tally1 in the report footer just gives me a zero. I tried using WhilePrintingRecords but it made no difference.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Dec 2009 at 6:04am
usually I will right a formula like:
shared numbervar Tally1;
Tally1
 
and then I place that formula wherever I want (sometimes in multiple places for debugging purposes)
IP IP Logged
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