Sub topic 8
Reading and writing structured references
This chapter assumes you can enter formulas, use A1-style references, and already have a named table (see the chapters on creating and naming tables). The examples use a table called SalesTable with the columns Region, Quantity, Unit Price and Amount.
What a structured reference is
A structured reference is a formula reference that uses the table name and column headers instead of cell addresses. It replaces =SUM(D2:D500) with =SUM(SalesTable[Amount]).
Two things make this useful:
- The reference follows the table. When rows are added or removed, the reference covers the new size.
- The formula reads like a description of the data.
Excel builds the reference from the table name and the header text. If either name changes, Excel updates every formula that uses it.
Anatomy of a reference
A reference has a table name, then one or more specifiers in square brackets.
| Reference | Meaning |
|---|---|
| `SalesTable[Amount]` | The data cells of the Amount column |
| `SalesTable[[#Headers],[Amount]]` | The header cell of that column |
| `SalesTable[[#Totals],[Amount]]` | The total row cell of that column |
| `SalesTable[#Data]` | All data cells, without headers or totals |
| `SalesTable[#All]` | The whole table, including headers and totals |
| `SalesTable[@Amount]` | The cell in the Amount column on the current row |
| `SalesTable[[Quantity]:[Amount]]` | Every column from Quantity to Amount |
Inside the table itself, you can drop the table name. [@Amount] and SalesTable[@Amount] mean the same thing. The @ symbol means "this row".
Writing references
You can type them, but pointing is usually faster. Start a formula with =, then click a column header or drag across column cells. Excel writes the structured reference for you. Typing =SUM(Sales also brings up an autocomplete list of table names and columns.
Here is a formula outside the table that totals one column:
=SUM(SalesTable[Amount])Here is a row-level formula in a new column:
=[@Quantity]*[@[Unit Price]]Notice [@[Unit Price]]. When a header contains a space or another special character, the name needs its own inner brackets. A header with a single quote, a hash, or a square bracket needs an extra escape character (') in front of that character.
Using references with other functions
Structured references work as arguments anywhere a range works. A conditional sum for one region looks like this:
=SUMIFS(SalesTable[Amount],SalesTable[Region],"North")For a lookup that stays correct as rows are added:
=XLOOKUP("North",SalesTable[Region],SalesTable[Amount])The same idea applies to the summing function the total row uses. SUBTOTAL(109,SalesTable[Amount]) ignores rows hidden by a filter, while SUM does not.
Common errors
#REF!after deleting a column. The formula pointed to a column that no longer exists. Restore the column or edit the formula.#NAME?after a typo. A misspelled table or column name is not recognized. Use autocomplete to avoid this.- Headers changed after writing formulas. Excel renames the references automatically when you edit a header in the table. Formulas in other workbooks that are closed may not update.
- Unwanted A1 references. If clicking cells inside a table writes
D2and not[@Amount], the option "Use table names in formulas" is off. Turn it on in File > Options > Formulas. @appearing in older formulas. In current Excel,[@Col]means the same row. A bare@before a function name is a different feature, implicit intersection, and is unrelated to tables.
Exercise
A table named OrdersTable has columns Item, Qty and Price. Write one formula for a cell outside the table that totals Qty, and one formula for a new column inside the table that gives Qty times Price for each row.
Show answer
Outside the table: =SUM(OrdersTable[Qty]). Inside the table, in a new column: =[@Qty]*[@Price]. Excel fills the second formula down the column as a calculated column.