5

I have some org-mode tables like this:

#+NAME: TableA
| Task | Amount |
|------+--------|
| Gna  |      1 |


#+NAME: TableB
| Task   | Amount |
|--------+--------|
| Gnampf |      3 |

| Overall | Amount |
|---------+--------|
|         |      4 |
|         |      3 |
#+TBLFM: @2$2=remote(TableA, @I$>)+remote(TableB, @I$>)::@3$2=vsum(remote(TableA, @I$>) remote(TableB, @I$>))

Using + to sum up the amounts in remote TableA and TableB works, but vsum doesn't. Why?

Bonus: If I have several of these tables, is there a way to iterate over all of them instead of enumerating them manually?

  • The argument or vsum have to be a vector, so `[remote(TableA, @I$>), remote([TableB, @I$>)]` instead of `remote(TableA, @I$>), remote(TableB, @I$>)`. – gigiair Apr 05 '22 at 13:33
  • @gigiair: I think that's correct. Can you make it into a proper answer? – NickD Apr 05 '22 at 14:04

1 Answers1

5

The argument of vsum has to be a vector, so use vsum([remote(TableA, @I$>), remote([TableB, @I$>)]) instead of vsum(remote(TableA, @I$>), remote(TableB, @I$>)).

Bonus

From your Org document, you can evaluate this code block:

#+BEGIN_SRC emacs-lisp :var basename="Table" start= (eval ?A) stop= (eval ?B)
   (append(list
     (format "Summary of tables from Table%c to Table%c" start stop) (format ":=%s"(mapconcat (lambda(x)(format "remote(Table%c,@>$2)" x))(number-sequence start stop) "+"))))
#+END_SRC

which returns

#+RESULTS:
| Summary of tables from TableA to TableB | :=remote(TableA,@>$2)+remote(TableB,@>$2) |

and evaluate it with Ctrl-c Ctrl-c

gigiair
  • 2,124
  • 1
  • 8
  • 14