Search code examples
emacsorg-mode

Recursive formulaes in org-mode tables


I have the following table:

| Year (Beginn) |    Price | Increase |
|---------------+----------+----------|
|          2016 | 20000.00 |  1000.00 |
|          2017 |          |  1000.00 |
|          2018 |          |  1000.00 |
|          2019 |          |  1000.00 |
|          2020 |          |  1000.00 |
|          2021 |          |  1000.00 |
|          2022 |          |  1000.00 |
|          2023 |          |  1000.00 |
|          2024 |          |  1000.00 |
|          2025 |          |  1000.00 |
|          2026 |          |  1000.00 |
|          2027 |          |  1000.00 |
|          2028 |          |  1000.00 |
|          2029 |          |  1000.00 |
|          2030 |          |  1000.00 |
|---------------+----------+----------|

I want to compute the price recursively such that the final table looks like this:

| Year (Beginn) |    Price | Increase |
|---------------+----------+----------|
|          2016 | 20000.00 |  1000.00 |
|          2017 | 22000.00 |  1000.00 |
|          2018 | 24000.00 |  1000.00 |
|          2019 | 26000.00 |  1000.00 |
|          2020 | 28000.00 |  1000.00 |
|          2021 | 30000.00 |  1000.00 |
|          2022 | 32000.00 |  1000.00 |
|          2023 | 34000.00 |  1000.00 |
|          2024 | 36000.00 |  1000.00 |
|          2025 | 38000.00 |  1000.00 |
|          2026 | 40000.00 |  1000.00 |
|          2027 | 42000.00 |  1000.00 |
|          2028 | 44000.00 |  1000.00 |
|          2029 | 46000.00 |  1000.00 |
|          2030 | 48000.00 |  1000.00 |
|---------------+----------+----------|

After reading a related SO question I tried the formula

#+TBLFM: @<<<..>$2=@<<..>>$2+2*$3

but it doesn't work. It gives an error and also seems to operate on column one instead of the specified column two. Any idea how to correctly compute column two? I am using org-mode version 8.2.5c with Emacs version 24.5.1.


Solution

  • I recommend using the following range formula:

    | Year (Beginn) |    Price | Increase |
    |---------------+----------+----------|
    |          2016 | 20000.00 |  1000.00 |
    |          2017 |          |  1000.00 |
    |          2018 |          |  1000.00 |
    |          2019 |          |  1000.00 |
    |          2020 |          |  1000.00 |
    |          2021 |          |  1000.00 |
    |          2022 |          |  1000.00 |
    |          2023 |          |  1000.00 |
    |          2024 |          |  1000.00 |
    |          2025 |          |  1000.00 |
    |          2026 |          |  1000.00 |
    |          2027 |          |  1000.00 |
    |          2028 |          |  1000.00 |
    |          2029 |          |  1000.00 |
    |          2030 |          |  1000.00 |
    |---------------+----------+----------|
    #+TBLFM: @<<<$2..@>$2=@<<$0+2*vsum(@<<$3..@-1$3);%.2f
    

    You could write a recursive formula, but that would propogate one row at a time. Even org-table-iterate (C-u C-u C-c * on any table cell) would have to be called more than once, since it stops after 10 iterations.