# calculate the sum of the muplication of 2 columns in org table

I have a org table:

``````| a | b | c |
|---+---+---|
| 1 | 2 | i |
| 3 | 4 | j |
|---+---+---|
| 4 | 6 |   |
``````

I want to multiply columns `a` and `b` and sum them up (except last row: `1*2+3*4`) and put into the last cell:

``````| a | b | c |
|---+---+---|
| 1 | 2 | i |
| 3 | 4 | j |
|---+---+---|
| 4 | 6 | 14|
``````

What is the formula to achieve this? I tried `#+TBLFM: @>\$>=sum(\$1 * \$2)` without luck.

My org version: Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @ /Applications/Emacs.app/Contents/Resources/lisp/org/)

• This is the scalar product of two vectors. Emacs calc (which is used by the table code in Org mode) can calculate the scalar product of two vectors using `*`, so the trick is to figure out how to specify the two vectors. @gigiair's answer shows you how to do that. Commented Feb 22, 2020 at 16:14

`````` @4\$3=(@2\$1..@3\$1)*(@2\$2..@3\$2)
``````

or

`````` @>\$>=(@<<\$<..@>>\$<)*(@<<\$<<..@>>\$<<)
``````

or

`````` @>\$>=(@I\$1..@II\$1)*(@I\$2..@II\$2)
``````

using the horizontal lines to delimit instead of explicit row numbers.

The relevant section of the manual is dense but well-worth reading (and re-reading).

• parentheses are not mandatory, but make the formula easyer to read. Commented Feb 22, 2020 at 8:19

You could use the `Orgtbl-Aggregate` package available on Melpa

The sums are in a separate table, easy to update

``````#+name: mytable
| a | b | c |
|---+---+---|
| 1 | 2 | i |
| 3 | 4 | j |

#+BEGIN: aggregate :table "mytable" :cols "vsum(a) vsum(b) vsum(a*b)"
| vsum(a) | vsum(b) | vsum(a*b) |
|---------+---------+-----------|
|       4 |       6 |        14 |
#+END:
``````