0

Rolling formulas are very common in accounting, for example, carrying forward a monthly balance based on expenses.

So say you had a table with month, beginning balance, fixed income, expenses, and net:

| month | balance |  income | expenses |     net |
|-------+---------+---------+----------+---------|
|     6 | 1000.00 | 1500.00 |   500.00 | 1000.00 |
|     7 | 2000.00 | 1500.00 |   500.00 | 1000.00 |
|     8 | 3000.00 | 1500.00 |   500.00 | 1000.00 |
|     9 | 4000.00 | 1500.00 |   500.00 | 1000.00 |

I know how to calculate the net column since that's just #+TBLFM: $5=$3-$4, but how about the balance column? The starting balance would be something you would have to manually enter based on when you started accounting, and expenses might change from month to month, but the goal would be to make it possible for the balance column to be calculated based on the previous row. Writing @2$2=@1$2 + @1$4::@3$2=@2$2 + @2$4 and so on for each row is tiring.

Is there a way to do this in org-mode?

1 Answer 1

1

Using relative row references it is possible to calculate balance from previous row.

With initial table and formula:

| month | balance |  income | expenses | net |
|-------+---------+---------+----------+-----|
|     6 |   1000. | 1500.00 |   500.00 |     |
|     7 |         | 1500.00 |   500.00 |     |
|     8 |         | 1500.00 |   500.00 |     |
|     9 |         | 1500.00 |   500.00 |     |
#+TBLFM: $2=@-1$2+@-1$5::$5=$3-$4::@2$2=1000.

pressing C-u C-c C-c to recompute entire table will give desired result:

| month | balance |  income | expenses |   net |
|-------+---------+---------+----------+-------|
|     6 |   1000. | 1500.00 |   500.00 | 1000. |
|     7 |   2000. | 1500.00 |   500.00 | 1000. |
|     8 |   3000. | 1500.00 |   500.00 | 1000. |
|     9 |   4000. | 1500.00 |   500.00 | 1000. |
#+TBLFM: $2=@-1$2+@-1$5::$5=$3-$4::@2$2=1000.

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.