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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Totals

Status
Not open for further replies.

bigpomp81

Programmer
Jun 3, 2004
5
US
I need a formula that takes a running total every record, for the last 15 records. Record 16 will have a sum of records 1-15, record 17 will have a sum of records 2-16.
 
Try something like the following except replace {EMPLOYEE.value} with your field:

numbervar array thenums;
numbervar counter;
numbervar temp;
if ubound(thenums) < 15 then
(
redim preserve thenums[ubound(thenums)+1];
thenums[ubound(thenums)]:={EMPLOYEE.value};
)
else if ubound(thenums) = 15 then
(
For Counter := 2 to 15 do(
thenums[ubound(thenums)-1]:=thenums[ubound(thenums)];
);
Thenums[15]:= {EMPLOYEE.value};
);
sum(TheNums)

Looks pretty close, hope it works for you.

-k
 
Here is a formula I have used for Rolling Totals.
It similar to synapsevampires but I think mine will satisfy your requirment - "Record 16 will have a sum of records 1-15, record 17 will have a sum of records 2-16":

Code:
numbervar the_field := {table.value}; //Replace with your field that has the value you want to total.
numbervar array Accum;
numbervar Rolling_Period := 15;

if OnFirstRecord then
    ReDim Accum [1]
else
    ReDim Preserve Accum [UBound(Accum)+1];
    
Accum [UBound(Accum)] := the_field;

If UBound(Accum) <= Rolling_Period then
    Sum(Accum) - the_field
Else
    sum(Accum[(UBound(Accum) - (Rolling_Period-1)) to UBound(Accum)]) - the_field;

~Brian
 
Thanks, where do I put the formula. In the running totals area or record selection?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top