1

Can I make table2 automatically recalculate a remote() formula when I modify data in table1?

I have the below tables and the first table is automatically recalculated when I press TAB (thanks to the "#" in the first column), but the second one it's only recalculated when move my cursor over it and press TAB in there as well.

I would like to have it recalculated when I change (TAB) the first table.

#+NAME: table1
| # | + Units | value | value2 |
|---+---------+-------+--------|
| # | unit1   |  3110 |    295 |
| # | unit2   |       |        |
| # | unit3   |       |        |
|---+---------+-------+--------|
| # | - Units | value | value2 |
|---+---------+-------+--------|
| # | unit1   |   -40 |        |
| # | unit2   |  -105 |        |
| # | unit3   |   -26 |        |
|---+---------+-------+--------|
| * | TOTAL:  |  2939 |    295 |
|---+---------+-------+--------|
#+TBLFM: @9$3=vsum(@-1..@1);EN::@9$4=vsum(@-1..@1);EN

#+NAME: table2
| # | TOTAL + |  3405 |
| # | TOTAL - |  -171 |   
#+TBLFM: @1$3=vsum(remote(table1,@I$3..@II$3))+vsum(remote(table1,@I$4..@II$4));EN::@2$3=vsum(remote(table1,@III$3..@IIII$3))+vsum(remote(table1,@III$4..@IIII$4));EN

I am aware that it might be possible using elisp code but would like to have it work with calc syntax, if possible.

  • Welcome! Does M-x org-table-recalculate-buffer-tables RET recalculate both tables? – Melioratus Feb 1 at 21:51
  • Yes, it does... – Sergiu Elmi Feb 1 at 21:58
  • 1
    I have used this command and bind it to <tab> alongside with org-cycle. Thank you. – Sergiu Elmi Feb 2 at 10:30
  • Thank you for posting the answer to your question! – Melioratus Feb 2 at 13:14
1

Not sure if this is the correct solution, or if I'll have trouble when the file gets bigger, with more tables, but it seems to work for the moment.

Solution: I have used a lambda function to bind both "org-cycle" and "org-table-recalculate-buffer-tables" to key and both tables are recalculated when I press it.

(add-hook 'org-mode-hook
      (lambda()
(local-set-key (kbd "<tab>") (lambda () (interactive) (org-cycle) (org-table-recalculate-buffer-tables)))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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