Compute a Running Sum

Top  Previous  Next

How To... > Work with Formulas > Work with the Formula Editor > Compute a Running Sum

Suppose you have a collection of daily sales receipts stored in an attribute named Receipts and you want to keep a running total.

1.Define a new attribute called RunningTotal.
2.Give it the formula prev(RunningTotal)+ Receipts

This works because the prev function for the first case returns 0, unless you specify otherwise. If you wanted the running total to reflect last month’s receipts, you would include that number. For example, if you wanted the initial value to be 1000, you would use this formula:

prev(RunningTotal,1000)+ Receipts