Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Multiplying rolling totals? Post Reply Post New Topic
Author Message
FunkyMunky
Newbie
Newbie


Joined: 03 Dec 2009
Online Status: Offline
Posts: 2
Quote FunkyMunky Replybullet Topic: Multiplying rolling totals?
     Posted: 03 Dec 2009 at 4:25pm
Hi, I've just recently started testing the waters a bit with Crystal Reports and have encountered what should be a pretty simple problem.  Given a database with multiple tables, how would it be possible to have a formula field take into account the previous calculated value?  I tried testing around with the rolling totals, but most of the functions weren't right for this purpose.  A ficticious example would be as follows:
 
Imagine if you had $1,000,000 invested somewhere and you had monthly returns, how would you calculate the month-end account value?  If let's say
 
Month                     Return                    Value
 
Jan                          5%                (1.05*1000000) = $1050000
Feb                         -2%               (0.98*1050000) = $1029000
Mar                         8%                (1.08*1029000) = $1111320
 
etc.
 
Thanks in advance
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 07 Dec 2009 at 6:11am
shared variables in a formula.  for the incrementing part:
shared numbervar aAmount;
aAmount := {table.percentReturn} * aAmount;
 
you might want to reset the variable, but that is up to you and the report layout.
 
HTH
IP IP Logged
FunkyMunky
Newbie
Newbie


Joined: 03 Dec 2009
Online Status: Offline
Posts: 2
Quote FunkyMunky Replybullet Posted: 07 Dec 2009 at 12:30pm
Hi, thanks for the response.
 
Is a loop of some sort necessary?  Most of my attempts prior to coming to these forums ended up yielding the initial $1,000,000 multiplied by whatever the month-end return was, without taking into account what the previous value was which obviously wouldn't be correct.
 
Using a shared variable along with that multiplication line just yielded the same results.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 08 Dec 2009 at 6:13am
no loop should be necessary.  I am assuming that the formula is in the detail section of the report.  CR is already reading the values from the table {table.percentReturn}.  The shared variable is multiplying by the previous result and saving it for use next time.
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