Next: , Previous: The spreadsheet, Up: The spreadsheet


3.5.1 References

To compute fields in the table from other fields, formulas must reference other fields or ranges. In Org, 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, or press C-c } to toggle the display of a grid.

Field references

Formulas can reference the value of another field in two ways. Like in any other spreadsheet, you may reference fields with a letter/number combination like B3, meaning the 2nd field in the 3rd row.

Org also uses another, more general operator that looks like this:

     @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 hline1, `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's references with unsigned numbers are fixed references in the sense that if you use the same reference in the formula for two different fields, the same field will be referenced each time. Org's references with signed numbers are floating references because the same reference operator can reference different fields depending on the field being calculated by the formula.

Here are a few examples:

     @2$3      2nd row, 3rd column
     C2        same as previous
     $5        column 5 in the current row
     E&        same as previous
     @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
Range references

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.
     A2..C4        Same as above.
     @-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.

Named references

`$name' is interpreted as the name of a column, parameter or constant. Constants are defined globally through the variable org-table-formula-constants, and locally (for the file) through a line like

     #+CONSTANTS: c=299792458. pi=3.14 eps=2.4e-6

Also properties (see Properties and Columns) can be used as constants in table formulas: For a property `:Xyz:' use the name `$PROP_Xyz', and the property will be searched in the current outline entry and in the hierarchy above it. 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 kilometers2. Column names and parameters can be specified in special table lines. These are described below, see Advanced features. All names must start with a letter, and further consist of letters and numbers.


Footnotes

[1] Note that only hlines are counted that separate table lines. If the table starts with a hline above the header, it does not count.

[2] Constant.el can supply the values of constants in two different unit systems, SI and cgs. Which one is used depends on the value of the variable constants-unit-system. You can use the #+STARTUP options constSI and constcgs to set this value for the current buffer.