Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SUM in crystal report without breaking group by! Post Reply Post New Topic
Author Message
cornall
Newbie
Newbie


Joined: 08 Apr 2009
Online Status: Offline
Posts: 5
Quote cornall Replybullet Topic: SUM in crystal report without breaking group by!
     Posted: 08 Apr 2009 at 6:25am

Hi,

If I have a table
 
String1         String2         Int
 
division a      person a       1
division a      person a       4
division a      person a       1
division a      person a       4
division a      person b       6
division a      person b       8
division b      person a       1
division b      person a       4
division b      person a       1
division b      person a       2
division b      person b       6
division b      person b       3
 
In SQL I would do the following to get a total for each person in each division
 
SELECT String1, String2, SUM (Int)
FROM MyTable
GROUP BY String1, String2
 
This would result in
 
division a      person a       10
division a      person b       14
division b      person a       8
division b      person b       9
 
I am new to crystal and would like to know how to achive the same
 
I add my table to the database fields section
 
In the group expert I select String1 and String2
 
If I view my report at this stage I get
 
division a      person a  
division a      person b  
division b      person a 
division b      person b 
 
As soon as I add a running total for int it breaks my group by clause and I get a row on my report for every row in my table.
 
This is driving me mad please help.
 
Thanks Dave
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Apr 2009 at 6:41am
When you say you add your table aer you adding it as the SQL statment above or just the straight table data?
If it is the straight table it sounds like you have 2 groupings
Group1 Division
Group 2 Person.
If this is correct you can handle this in a couple of ways.
You can use a SUM function to SUM int at group level 2 (person). A Summary can be moved to a group header. 
Or use a running total as a SUM of int that is reset at group level 2. Running totals must be on footers.
Does this answer your question?
 
IP IP Logged
cornall
Newbie
Newbie


Joined: 08 Apr 2009
Online Status: Offline
Posts: 5
Quote cornall Replybullet Posted: 08 Apr 2009 at 6:56am
Hi,
 
I am adding it as straight table data and have the two groupings your described.
 
I have group by on server selected and this works until I add a SQL Expression to do the count or SUM. The group by dissapears from the SQL generated by Crystal.
 
I want the data to appear in one row
 
person division total
 
so I can't use summay
 
If I use running total this also removes the GROUP by clause as I am introducing a 3rd field.
 
Thanks for the rapid response. Hope this extra info helps explain.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Apr 2009 at 7:07am
When you say you want one row you mean one row per peron at each division with a sum, correct?
If so son't bother with a SQL statement.
Add your table.
Group on Division. Right click on the division group field and select Format field. Select Common tab and check the "suppress" box.
Add in group 2 as person. slide it to the right on the header field.
Add the division field (not the group but just the field) on group header 2 just to the left of your person group name.
Click on INsert Summary function (sigma sign).
Field to summarize is your "int" field.
Calculate as SUM
Summary Location is group level 2 (person level).
it will default to the group2 footer. Grab it and move it to group header2 just to the right of your person name.
Go into the secion expert.
Click on Report header 1 and select SUppress Blank section.
click on details, group footer 1 and 2 and do the same thing.
Preview your report.
See if this is what you wanted.
If not, let me know what is not showing correctly.
IP IP Logged
cornall
Newbie
Newbie


Joined: 08 Apr 2009
Online Status: Offline
Posts: 5
Quote cornall Replybullet Posted: 08 Apr 2009 at 7:19am

Hi,

Thanks again. I followed the instructions exactly. I had already added it as a table sorry my mention of SQL was missleading.

 
Two problems.
 
 
1. It won't let me move the summary out the footer into the detail section.
 
2. As soon as I add the summary colum the grouping no longer works and I get a row for every person and division row rather than a single person per division with a sum total!!!
 
e.g
 
division 1           sales person1
division 1           sales person2
division 1           sales person3
.....
 
becomes
 
division 1           sales person1
division 1           sales person1
division 1           sales person1
                                  33
division 1           sales person2
division 1           sales person2
division 1           sales person2
                                   14
division 1           sales person3
division 1           sales person3
division 1           sales person3
                                  22
....
 
 
 


Edited by cornall - 08 Apr 2009 at 7:19am
IP IP Logged
cornall
Newbie
Newbie


Joined: 08 Apr 2009
Online Status: Offline
Posts: 5
Quote cornall Replybullet Posted: 08 Apr 2009 at 7:22am
Boom it hit me!! I should be using the group 2 header not the detail area!! It is working now.
 
Thanks ever so much for all your help. Appreciated. Hopefully one day I can give somethign back!!
 
Cheers Dave
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