Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate Accumulated amount?

Status
Not open for further replies.

jayc

Programmer
Jan 13, 2002
7
MY

I having problem here with finding the accumulated amount. This is what i want to do:

RecNo Amount Accumulated Amount
1 500.00 0.00
2 2000.00 500.00
3 1500.00 2500.00
4 3000.00 4000.00

What formula should i use to find the accumulated amount?Pls help. Thank you.
 
Try this : It may work :

Whileprintingrecords;
numbervar var1;
var1:=var1+amount;


the token whileprintingrecords might solve your porblem.
If It doesn't work.Let me know.
 
JayC-

if you are using version 7 or newer of crystal reports, forget variables and just add running total field(s). Much easier.

Software Support for Sage Mas90, Macola, Crystal Reports, Goldmine and MS Office
 
Thanks Hattusas for you solution. It works!
I am using version 4.6
 
JayC????
I was very surprised that it worked :).Because when I wrote my formula it worked like adding a running total but "adding a running total doesn't solve your problem."
Because when adding running total the result will be

Amount Running total
2 2
3 5
4 9
etc.
In order to obtain the cumulative sum.

Amount Running total
2 0
3 2
4 5
You will have to use formulas.
Since I want my cumulative sum from 0 I must create something tricky.
First on your "report header" add this formula :
whileprintingrecords;
numbervar y:=0;
Then on your section where amount fields lies add this formula :
Whileprintingrecords;
numbervar x;
numbervar y;
numbervar z;
if (y=0)then
(
y:=y+1;
z:=z+{your database field};
)
else
x:=x+z;
z:={your database field};
x
This formula will result the following.

Amount Running total
2 0
3 2
4 5
As a summary formulas are a little bit tiring BUT they are very flexible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top