4

Is it possible to write an org table colmun formula which calculates the running total of some other column? Here is a simple example of the idea: The table

|  1 |   |
|  2 |   |
|  5 |   |
| 10 |   |

should be endowed with a column formula which gives the resulting table

|  1 |  1 |
|  2 |  3 |
|  5 |  8 |
| 10 | 18 |

1 Answer 1

5

You can add from the first row to the current row thus:

| value | accum |
|-------+-------|
| 1     | 1     |
| 2     | 3     |
| 5     | 8     |
| 10    | 18    |
|-------+-------|
#+TBLFM: $2=vsum(@I$1..$1)

@I refers to the row after the first hline. If you don't want headings in your table, use @1 instead.

Of course this is not super efficient for large tables since the whole sum is calculated each time. You can calculate the sum progressively as follows:

| value | accum |
|-------+-------|
| 1     | 1     |
| 2     | 3     |
| 5     | 8     |
| 10    | 18    |
|-------+-------|
#+TBLFM: @2$2=$1::$2=$1+@-1

although I'm not sure if this second method is faster.

1
  • The second one requires the formula to be evaluated twice, in order to converge on the correct result.
    – jacg
    Commented Sep 6, 2016 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.