# Org mode: Insert the result of a table formula between two existing columns

I have a very simple table like this:

``````| A | B |  C |
|---+---+----|
| 1 | 2 | 15 |
| 1 | 2 | 32 |
| 1 | 2 | 81 |
``````

I want to apply a formula that calculate the sum between A and B and insert the result just after the B column but before the C one. The formula is easy but…

``````#+TBLFM: \$? = \$1+\$2
``````

…I don't know what to put in place of `\$?`.

How can I achieve that?

• Adding a column is a one-time operation that is best done through external means, not through a formula. While in column `C`, say `M-x org-table-insert-column` which inserts an empty third column, leaving the formula then as `\$3 = \$1 + \$2`. Aug 1, 2021 at 0:59
• I agree with @NickD. It would be helpful to know why you are trying to add one more column to the table. Thus, we would know whether this is a XY problem. Aug 9, 2021 at 4:24

An elisp formula can do the trick :

``````  | A | B |   |  C |
|---+---+---+----|
| 1 | 2 | 3 | 15 |
| 1 | 2 | 3 | 32 |
| 1 | 2 | 3 | 81 |
#+TBLFM: \$4='(progn(org-table-analyze)(when (eq 3 org-table-current-ncol) (org-table-insert-column)) (+ \$1 \$2));N
``````
• It doesn't work for me, it produces a weird result. Care to elaborate on what does this elisp formula do? Aug 1, 2021 at 10:19
• The trouble with using a formula to do this, is that the next time you refresh the table, the formula is applied again (and again and again...) For non-idempotent operations, this is obviously going to cause problems. That's why I recommended that for such one-time operations, you do NOT use a formula (or if you do, you then delete the part of the formula that does that particular operation. Aug 1, 2021 at 13:15
• It works the first time, but try doing `C-c C-c` on your formula a second time: what do you see? Aug 1, 2021 at 13:17
• @Nicryc. Your question is certainly part of a much larger question, the context of which I do not know and which should be treated as such. My solution is kind of a joke of taking your question at face value. At home it works, but I will not use such a solution under any circumstances. Aug 1, 2021 at 13:34
• It's hard to show it here so I'm just gonna describe it. It creates two new columns (`\$4` and `\$5`) and put the result of the first row in the `\$5` column and the result of the following rows in the `\$4` column. Besides it automatically change the beginning of my formula to `\$5=`. I know this is some weird question but in fact my tables are completely re-generated each time I change some values in a bigger root table using the org-aggregate module. Aug 1, 2021 at 15:35