Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Need help with summary/group calculation Post Reply Post New Topic
Author Message
J2112
Newbie
Newbie


Joined: 09 Apr 2009
Online Status: Offline
Posts: 7
Quote J2112 Replybullet Topic: Need help with summary/group calculation
     Posted: 09 Apr 2009 at 12:02pm
This is probably simple, but I have a report with line-item sales data that is totaled/grouped by item, by customer, by sales rep. The columns are 2008 sales and 2009 sales. I need to calculate the % change from 08 to 09 for each summary group. Like this:

.........................Sales08....Sales09....%Diff
Item
..Customer
....Rep
......Report

I have the formula to do the calculation but I'm not sure how to create the field for each group footer to do the calculation. I've tried it as a formula field and a SQL field and I can't get it. I'm using CR v10. Thanks.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 10 Apr 2009 at 6:19am
You would need a formula for each grouping, at least that is how I would do it...
 
Since you are summing in the footer, and I am hoping that there are no items that are being skipped via a suppression formula something like this shoud work:
 
SUM({table.field08}, {Item grouping}) / SUM({table.field09}, {Item grouping})
 
 
Each level would use the correct {group condition} for the summing.
 
Hope this helps
IP IP Logged
J2112
Newbie
Newbie


Joined: 09 Apr 2009
Online Status: Offline
Posts: 7
Quote J2112 Replybullet Posted: 10 Apr 2009 at 2:45pm
Thanks for the suggestion.

Can I use an IF statement in a formula field?

The basic calculation I'm doing is (SUM09 - SUM08) / SUM08 * 100 to get the %Diff, however I do have some customers that have 0 sales for 08 and I anticipate getting the infamous "division by 0" message.  I'm just not sure how to incorporate a condition that says if SUM08 = 0, then %Diff = 0, else (..above calculation..)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Apr 2009 at 2:50pm
if SUM08= 0 then 0 else (SUM09 - SUM08) % SUM08
IP IP Logged
J2112
Newbie
Newbie


Joined: 09 Apr 2009
Online Status: Offline
Posts: 7
Quote J2112 Replybullet Posted: 14 Apr 2009 at 9:33am
I'm not getting any further.... any other suggestions?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Apr 2009 at 9:59am
What exactly are you stuck on? An error from that formula or something else?
IP IP Logged
J2112
Newbie
Newbie


Joined: 09 Apr 2009
Online Status: Offline
Posts: 7
Quote J2112 Replybullet Posted: 15 Apr 2009 at 10:11am
If I keep the "formula =" in the formula field then I get an error at the IF statement.  If I remove the "formula =" then I get an error at the "0" after the THEN statement (says a statement is expected?).
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Apr 2009 at 10:26am
What DBlank wrote is all that you need the formula...Are you using Crystal or Basic syntax.  DBlank's solution is all that is needed in Crystal syntax.
IP IP Logged
J2112
Newbie
Newbie


Joined: 09 Apr 2009
Online Status: Offline
Posts: 7
Quote J2112 Replybullet Posted: 15 Apr 2009 at 10:31am
Ah I was using Basic syntax.... works now.  Thanks for clearing that up!
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