Next: Formula syntax for Calc, Previous: The spreadsheet, Up: The spreadsheet
To compute fields in the table from other fields, formulas must reference other fields or ranges. In Org-mode, fields can be referenced by name, by absolute coordinates, and by relative coordinates. To find out what the coordinates of a field are, press C-c ? in that field.
Formulas can reference the value of another field with the operator
@row$column
Column references can be absolute like `1', `2',...`N', or relative to the current column like `+1' or `-2'.
The row specification only counts data lines and ignores horizontal separator lines (hlines). You can use absolute row numbers `1'...`N', and row numbers relative to the current row like `+3' or `-1'. Or specify the row relative to one of the hlines: `I' refers to the first hline, `II' to the second etc. `-I' refers to the first such line above the current line, `+I' to the first such line below the current line. You can also write `III+2' which is the second data line after the third hline in the table. Relative row numbers like `-3' will not cross hlines if the current line is too close to the hline. Instead, the value directly at the hline is used.
`0' refers to the current row and column. Also, if you omit either the column or the row part of the reference, the current row/column is implied.
Org-mode's references with positive numbers correspond to fixed
references in other spreadsheet programs. For example, @3$28
corresponds to $AB$3. Org-mode's references with negative
numbers behave similar to non-fixed references in other spreadsheet
programs, because when the same formula is used in several fields,
different fields are referenced each time.
Here are a few examples:
@2$3 2nd row, 3rd column $5 column 5 in the current row @2 current column, row 2 @-1$-3 the field one row up, three columns to the left @-I$2 field just under hline above current row, column 2
You may reference a rectangular range of fields by specifying two field
references connected by two dots `..'. If both fields are in the
current row, you may simply use `$2..$7', but if at least one field
is in a different row, you need to use the general @row$column
format at least for the first field (i.e the reference must start with
`@' in order to be interpreted correctly). Examples:
$1..$3 First three fields in the current row. $P..$Q Range, using column names (see under Advanced) @2$1..@4$3 6 fields between these two fields. @-1$-2..@-1 3 numbers from the column to the left, 2 up to current row
Range references return a vector of values that can be fed into Calc vector functions. Empty fields in ranges are normally suppressed, so that the vector contains only the non-empty fields (but see the `E' mode switch below). If there are no non-empty fields, `[0]' is returned to avoid syntax errors in formulas.
`$name' is interpreted as the name of a column, parameter or
constant. Constants are defined globally through the variable
org-table-formula-constants. If you have the
constants.el package, it will also be used to resolve
constants, including natural constants like `$h' for Planck's
constant, and units like `$km' for kilometers. Column names and
parameters can be specified in special table lines. These are
described below, see Advanced features.