Skip to content

Calculate a Table

Open costs.org with C-x C-f. Type or paste:

| Item | Quantity | Price | Total |
|------+----------+-------+-------|
| Pencil | 2 | 1.50 | 0 |
| Notebook | 1 | 4.00 | 0 |
#+TBLFM: $4=$2*$3;%.2f

Align the rows

Place the cursor inside a table row and press C-c C-c. rev aligns the columns. Tab moves to the next field; Shift-Tab moves to the previous one.

The table now looks like this:

| Item     | Quantity | Price | Total |
|----------+----------+-------+-------|
| Pencil   |        2 |  1.50 |     0 |
| Notebook |        1 |  4.00 |     0 |

Calculate the totals

With the cursor still in the table, run M-x org-table-recalculate. The Total cells become 3.00 and 4.00. The formula multiplies the second and third columns and displays two decimal places in the fourth.

After recalculation, with alignment applied:

| Item     | Quantity | Price | Total |
|----------+----------+-------+-------|
| Pencil   |        2 |  1.50 |  3.00 |
| Notebook |        1 |  4.00 |  4.00 |

Save with C-x C-s.

Try changing the pencil quantity to 3 and recalculating. Its total becomes 4.50. Formulas run only when you request them; editing a value does not automatically recalculate the table.

The table reference describes sums, rounding, row and column editing, and import/export. rev supports a bounded numeric formula language; it does not evaluate Emacs Lisp or the full Emacs Calc language.

Continue from the Org mode guide for capture, source blocks, exports and the complete Org reference.

Previous · Org mode guide