Next: , Previous: , Up: The Spreadsheet   [Contents][Index]


3.5.5 Field and range formulas

To assign a formula to a particular field, type it directly into the field, preceded by ‘:=’, for example ‘vsum(@II..III)’. When you press TAB or RET or C-c C-c with point still in the field, the formula is stored as the formula for this field, evaluated, and the current field is replaced with the result.

Formulas are stored in a special ‘TBLFM’ keyword located directly below the table. If you type the equation in the fourth field of the third data line in the table, the formula looks like ‘@3$4=$1+$2’. When inserting/deleting/swapping column and rows with the appropriate commands, absolute references (but not relative ones) in stored formulas are modified in order to still reference the same field. To avoid this from happening, in particular in range references, anchor ranges at the table borders (using ‘@<’, ‘@>’, ‘$<’, ‘$>’), or at hlines using the ‘@I’ notation. Automatic adaptation of field references does not happen if you edit the table structure with normal editing commands—you must fix the formulas yourself.

Instead of typing an equation into the field, you may also use the following command

C-u C-c = (org-table-eval-formula)

Install a new formula for the current field. The command prompts for a formula with default taken from the ‘TBLFM’ keyword, applies it to the current field, and stores it.

The left-hand side of a formula can also be a special expression in order to assign the formula to a number of different fields. There is no keyboard shortcut to enter such range formulas. To add them, use the formula editor (see Editing and debugging formulas) or edit the ‘TBLFM’ keyword directly.

$2=

Column formula, valid for the entire column. This is so common that Org treats these formulas in a special way, see Column formulas.

@3=

Row formula, applies to all fields in the specified row. ‘@>=’ means the last row.

@1$2..@4$3=

Range formula, applies to all fields in the given rectangular range. This can also be used to assign a formula to some but not all fields in a row.

$NAME=

Named field, see Advanced features.


Next: , Previous: , Up: The Spreadsheet   [Contents][Index]