Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: totalling a shared variable Post Reply Post New Topic
Author Message
ramon010
Newbie
Newbie


Joined: 19 Nov 2011
Online Status: Offline
Posts: 1
Quote ramon010 Replybullet Topic: totalling a shared variable
     Posted: 19 Nov 2011 at 11:54am
Hi.

I have a report with two subgroups: 

SB1   Teacher
SB2   Subject

I also have a subreport which is linked by Subject to the main report.  I the subreport, I have a calculated field showing the average grade of students in the subject - avgrd.  The subreport is in GH2.

In GF2, avgrd is showing correctly.

I want to show a variable in GF1 that will calculate the average grade of all students under the same teacher by adding all the avgrd returned from the subreport and displayed in GF2 / the number of subjects handled by that teacher.

I was able to summarize the above by using a local variable and another shared variable.  In the main report using a variable that contains the following:

whileprintingrecords;
SHARED Numbervar avgrd;
SHARED Numbervar tavrg;
Local Numbervar a;
a:= avgrd;
tavrg:= tavrg + a;
avgrd

THEN, in GF1, I placed a variable with the following formula:

whileprintingrecords;
SHARED Numbervar tavrg;
tavrg

My problem now is that tavrg does not reset for every change in the teacher group.

Ideas please?   Thank you.
 


Edited by ramon010 - 19 Nov 2011 at 3:37pm
IP IP Logged
rahmaniac22
Newbie
Newbie


Joined: 24 Feb 2010
Location: United States
Online Status: Offline
Posts: 14
Quote rahmaniac22 Replybullet Posted: 21 Nov 2011 at 4:24am
Please use the formula with the group name  {fieldname, groupname}
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 21 Nov 2011 at 5:05am
in the group header place a formula like:
shared numbervar tavrg := 0;
"" //hides the reset
 
just as a note, you do realize the average of a group of averages is not really the average.  What would probably be a more accurate number would be to use shared variables and return the sums and counts of the classes so that an average can be computed.
 
just a thought,
 
HTH
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