Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Percentages? Post Reply Post New Topic
Author Message
JDodd
Newbie
Newbie


Joined: 01 Mar 2007
Online Status: Offline
Posts: 15
Quote JDodd Replybullet Topic: Percentages?
     Posted: 19 Feb 2008 at 1:50pm

Hi all,

Here is my situation.  I'm trying to produce a report that will show a percentage increase or decrease on the average value of our invoices by year.  I currently have a report grouped by year that shows me the average value of the invoices for that year.  How do I reference the average value from a prior year to calculate the percent change for the current year.  For eaxmaple:
 
 
Year   Average Amt     % Change
2005     530.00                                          <-----group Header Level
2006     526.00                -0.75%               <-----group Header Level
2007     382.00                -27.38%             <-----group Header Level
2008     270.00                -29.32%             <-----group Header Level
 
Any help would be greatly appreciated.
 
Thanks in advance.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 19 Feb 2008 at 10:46pm
I would do it by creating a shared variable that stores the value of the current average amount. Then on the next record, first calculate what the percent change is and then update the average amount variable to be the current average amount value. Something like this (you'll have to tweak it):
Shared NumberVar AvgAmt;
NumberVar PctChange;
//If there was a previous record, calculate the percent change
if AvgAmt>0 then
(
    PctChange := ({AverageAmountField} - AvgAmt)/{AverageAmountField};
)
//Update the average amount for the current record
AvgAmt := {AverageAmountField};
PctChange;

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
JDodd
Newbie
Newbie


Joined: 01 Mar 2007
Online Status: Offline
Posts: 15
Quote JDodd Replybullet Posted: 20 Feb 2008 at 10:13am
Thank you so much.  Worked perfectly.
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