# 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 second field in the third row. However, Org prefers to use another, more general representation that looks like this:^{1}

`@ROW$COLUMN`

Column specifications can be absolute like β`$1`

β, β`$2`

β, β¦, β`$N`

β, or relative to the current column, i.e., the column of the field which is being computed, like β`$+1`

β or β`$-2`

β. β`$<`

β and β`$>`

β are immutable references to the first and last column, respectively, and you can use β`$>>>`

β to indicate the third column from the right.

The row specification only counts data lines and ignores horizontal separator lines, or βhlines". Like with columns, you can use absolute row numbers β`@1`

β, β`@2`

β, β¦, β`@N`

β, and row numbers relative to the current row like β`@+3`

β or β`@-1`

β. β`@<`

β and β`@>`

β are immutable references the first and last row in the table, respectively. You may also 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.

β`@0`

β and β`$0`

β refer to the current row and column, respectively, i.e., to the row/column for the field being computed. 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 is 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 (same as β`C2` β) |

β`$5` β | column 5 in the current row (same as β`E&` β) |

β`@2` β | current column, row 2 |

β`@-1$-3` β | field one row up, three columns to the left |

β`@-I$2` β | field just under hline above current row, column 2 |

β`@>$5` β | field in the last row, in column 5 |

## Range referencesβ

You may reference a rectangular range of fields by specifying two field references connected by two dots β`..`

β. The ends are included in the range. 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 Advanced features) |

β`$<<<..$>>` β | start in third column, continue to the last but one |

β`@2$1..@4$3` β | nine fields between these two fields (same as β`A2..C4` β) |

β`@-1$-2..@-1` β | 3 fields in the row above, starting from 2 columns on the left |

β`@I..II` β | between first and second hline, short for β`@I..@II` β |

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. For other options with the mode switches β`E`

β, β`N`

β and examples, see Formula syntax for Calc.

## Field coordinates in formulasβ

One of the very first actions during evaluation of Calc formulas and Lisp formulas is to substitute β`@#`

β and β`$#`

β in the formula with the row or column number of the field where the current result will go to. The traditional Lisp formula equivalents are `org-table-current-dline`

and `org-table-current-column`

. Examples:

### β`if(@# % 2, $#, string(""))`

ββ

Insert column number on odd rows, set field to empty on even rows.

### β`$2 = '(identity remote(FOO, @@#$1))`

ββ

Copy text or values of each row of column 1 of the table named `FOO`

into column 2 of the current table.

### β`@3 = 2 * remote(FOO, @1$$#)`

ββ

Insert the doubled value of each column of row 1 of the table named `FOO`

into row 3 of the current table.

For the second and third examples, table `FOO`

must have at least as many rows or columns as the current table. Note that this is inefficient^{2} for large number of rows.

## 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 this example:

`#+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 kilometers^{3}. 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.

## Remote referencesβ

You may also reference constants, fields and ranges from a different table, either in the current file or even in a different file. The syntax is

`remote(NAME,REF)`

where `NAME`

can be the name of a table in the current file as set by a β`#+NAME:`

β line before the table. It can also be the ID of an entry, even in a different file, and the reference then refers to the first table in that entry. `REF`

is an absolute field or range reference as described above for example β`@3$3`

β or β`$somename`

β, valid in the referenced table.

When `NAME`

has the format β`@ROW$COLUMN`

β, it is substituted with the name or ID found in this field of the current table. For example β`remote($1, @@>$2)`

β β β`remote(year_2013, @@>$1)`

β. The format β`B3`

β is not supported because it can not be distinguished from a plain table name or ID.

- Org understands references typed by the user as β
`B4`

β, but it does not use this syntax when offering a formula for editing. You can customize this behavior using the variable`org-table-use-standard-references`

.β© - The computation time scales as O(N^2) because table
`FOO`

is parsed for each field to be copied.β© - The file β
`constants.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.β©