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.

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

1 Answer 1

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)))))
1
  • Yes, but ... you have now tied two different functions to the same key with no way of disentangling them. Now pressing TAB anywhere in the file (including when you are not in a table) will recalculate every table in the file. It would be better if you bound org-table-recalculate-buffer-tables to a different key (e.g. C-c z which is usually free) and leave TAB alone.
    – NickD
    Commented Dec 14, 2022 at 2:52

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.