Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Topic: how can I get the sum of fields in group Post Reply Post New Topic
Author Message
haivy
Newbie
Newbie


Joined: 18 Jun 2009
Online Status: Offline
Posts: 5
Quote haivy Replybullet Topic: Topic: how can I get the sum of fields in group
     Posted: 18 Jun 2009 at 4:23am
example:
fieldA fieldB
2 30 group1
2 10
5 12 group2
5 14
5 9 group3
8 1
8 9

the values of fieldA in a group are the same.
what i want is  to calculate fieldA of each group only once: 2+5+8
how can i do this and display the sum at the report header?
 
"running total fields" only sumarizes the first record!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 18 Jun 2009 at 7:26am
Not sure how you are going to do this and display it in the report header without a sub report.
Any formula or Running Total is going to have to be placed in the footer to give you the correct value.
You can create a sub report and use a RT and place the sub-report in the header.
IP IP Logged
Seva
Newbie
Newbie
Avatar

Joined: 01 May 2008
Location: United States
Online Status: Offline
Posts: 10
Quote Seva Replybullet Posted: 18 Jun 2009 at 8:50am
First you have to group your report on Quantity.
It gives you one record for each quantity on group level, and
GroupName as numeric value what you will be operating.
 
After it you have to assign variable and to sumarize it as:
 
whileprintingrecords;
global nubervar nQty := nQty + GroupName;
 
this formula will be in your new Group header or footer.
And you can suppress it
 
Now you have to display your calculations at the end of the report,
in the report footer:
 
whileprintingrecords;
global nubervar nQty;
 
Because it's global, you probably would be able to display it in the
report header.
If it wouldn't work, well, you will have to build subreport, same
what your main report, put it in main report header and display
summary result what you receive in subreport with same technic
what I described earlier.
Only in this case you don't need to declare "global".
Just variable nubervar nQty
IP IP Logged
haivy
Newbie
Newbie


Joined: 18 Jun 2009
Online Status: Offline
Posts: 5
Quote haivy Replybullet Posted: 19 Jun 2009 at 2:22am
thanks for your help.
i tried but it seems that dosen't work well.
liked the "running total field" in the report header, field A values only summarized once in the sub report....
 
best regards
IP IP Logged
Seva
Newbie
Newbie
Avatar

Joined: 01 May 2008
Location: United States
Online Status: Offline
Posts: 10
Quote Seva Replybullet Posted: 19 Jun 2009 at 6:46am
what "doesn't work well"?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Jun 2009 at 7:07am

the formula needs to evaluate the information as it is being read and threfore cannot be placed in a header. If you do that it will only have read the first record and have applied the formula to that. This is the same issue as with a Running Total. This is why I originally suggested a sub report. It can evaulate the entire set of data by placing the total in its footer and that can be displayed in the header of the main report.

IP IP Logged
haivy
Newbie
Newbie


Joined: 18 Jun 2009
Online Status: Offline
Posts: 5
Quote haivy Replybullet Posted: 21 Jun 2009 at 6:13pm
thank you everyone.
i've solved it using a subreport.
thanks again!
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 22 Jun 2009 at 2:51am

Hey All,

Not sure but couldn't this also be done with a shared variable ?
on detail :
local numbervar MAX
MAX := fieldA
 
on group a MAX summary of field MAX
and in the footer a sum from that field ?
 
Maybe you will need to use a second formula field on the group lvl to store the maximum value of MAX.
 
or am i compleet wrong with this ?
 
Greets
 
Tom
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