Sub topic 7
Naming a table and using it in formulas
This chapter assumes you can already convert a range to a table and read its parts: the header row, the columns, and the table menu. It also assumes you can write simple formulas such as SUM and know A1 notation. The goal here is to replace cell addresses with names. A formula like =SUM(C2:C4) ties itself to one block of cells. A formula like =SUM(Orders[Amount]) ties itself to a column of a table, so it keeps working as the table changes.
Why the name matters
When you convert a range to a table, Google Sheets gives the table a default name such as Table1. That name is a handle you can use inside any formula in the spreadsheet. A formula that uses the handle does not store cell addresses. It stores the table name and a column name, and Sheets works out the cells each time it calculates.
That gives you three practical benefits:
- Formulas read like sentences.
Orders[Amount]says what the data is.C2:C4only says where it is. - Formulas follow the data. If rows are added to the table, the reference covers them without you editing anything.
- Formulas survive moves. If you move the table to another sheet or insert columns before it, the name still points at the same data.
The next chapter covers how the table grows. This chapter focuses on the naming and referencing side.
Naming a table
A good name is the first step. Table1, Table2, and Table3 tell you nothing when you read a formula three months later.
How to rename
- Click anywhere inside the table.
- Find the table name shown at the top left of the table, above the header row.
- Click the name and type a new one.
- Press Enter to confirm.
If your version of the interface shows the name somewhere slightly different, look in the table menu. It is the same control that holds the column-type and formatting options you met earlier.
Choosing a good name
Treat table names like names in code. They must be typed inside formulas, so short, clear, and predictable names work best.
- Use letters, numbers, and underscores. Avoid spaces. Use
SalesOrdersorSales_Orders, notSales Orders. - Start the name with a letter or an underscore, not a digit.
- Make the name describe one row.
Ordersmeans each row is an order.Customersmeans each row is a customer. - Keep each name unique in the spreadsheet. Two tables cannot share one name.
- Do not choose a name that looks like a cell address, such as
Q1orA2. Sheets may reject it or confuse it with a cell.
If Sheets refuses a name, it shows a message in the name box. Shorten the name or remove punctuation and try again.
The structured reference
A reference that uses a table name and a column name is called a structured reference. It has this shape:
TableName[ColumnName]The column name is the text in the header cell. In the sample table from earlier in this tutorial, the columns are Order ID, Customer, Order Date, Amount, and Paid. Once the table is named Orders, these references work:
| Reference | What it points to |
|---|---|
| `Orders[Amount]` | Every value in the Amount column, excluding the header |
| `Orders[Customer]` | Every value in the Customer column |
| `Orders[Paid]` | Every checkbox in the Paid column |
| `Orders[#HEADERS]` | The header row only |
| `Orders[#ALL]` | The whole table including the header row |
The #HEADERS and #ALL forms are useful when you want the labels along with the data, for example as input to a function that expects a header row. Type Orders[ in a cell and use the autocomplete list to see exactly which forms your version of Sheets offers.
Replacing a fixed range
Here is the traditional formula from the sample data:
=SUM(C2:C4)It sums three cells. If you add a fourth order in row 5, the formula does not include it unless you edit the reference. Note also that the range in this sample is column C, but in the table the Amount column is the fourth column. The formula only works because someone checked the address by hand.
The structured version is:
=SUM(Orders[Amount])There is no address to get wrong. The formula names the column, and Sheets finds it.
Counting and conditions
Structured references work wherever a range works. This formula counts the paid orders:
=COUNTIF(Orders[Paid], TRUE)Because Paid is a checkbox column, its values are TRUE or FALSE. The formula counts the TRUE values. With the sample data the result is 2.
You can combine columns in the usual ways. This one totals the amount for one customer:
=SUMIF(Orders[Customer], "Acme", Orders[Amount])And this one totals only unpaid orders:
=SUMIF(Orders[Paid], FALSE, Orders[Amount])With the sample data, the first returns 250 and the second returns 480.
Typing structured references
You rarely need to type a full reference by hand.
- Autocomplete. Start typing a table name in a formula. Sheets suggests matching table names. After you type the opening bracket, it suggests column names.
- Point and click. While editing a formula, click a column header or a column in the table. Sheets inserts the structured reference instead of a cell range. Check the result in the formula bar, because the inserted text shows exactly what Sheets understood.
If autocomplete does not list your table, check that the name is spelled as you expect. A table you have just renamed shows its new name immediately.
Column names with special characters
Column headers often contain spaces or punctuation, such as Order ID or Amount (USD). Simple names with letters and numbers work as in the examples above. Names with spaces and symbols can be more fragile.
Two habits keep you out of trouble:
- Let autocomplete insert the column name for you, so the escaping is correct.
- Prefer plain headers when you design the table.
OrderDateis easier to reference thanOrder date (UTC).
What happens when things change
The reason to use names is that formulas keep their meaning when the sheet changes. The table below summarizes the common events.
| Event | Effect on `=SUM(Orders[Amount])` |
|---|---|
| You add a row to the table | The new row is included automatically |
| You delete a row from the table | The row is removed from the total |
| You sort or filter the table | The formula still refers to the whole column. Filtering does not change what `SUM` adds, because the hidden rows remain in the table |
| You rename the table | Sheets rewrites the formula to use the new name |
| You rename the column header | Sheets rewrites the formula to use the new header text |
| You move the table | The formula still finds the data |
| You delete the column | The formula returns an error such as `#REF!` |
| You convert the table back to a range | The reference is converted or can break. See the chapter on converting a table back to a range |
The filter row deserves attention. A filter hides rows from view, but SUM still adds the hidden values because the structured reference covers the full column. If you want a total of only the visible rows, use SUBTOTAL or AGGREGATE with a range reference instead. Test the result on a small sample before you trust it in a report.
How a formula resolves a reference
This diagram shows what Sheets does with =SUM(Orders[Amount]) each time it recalculates.
Because the lookup happens at calculation time, adding a row changes step D and nothing else. You do not touch the formula.
Common errors
These problems account for most failures with structured references.
- A misspelled table or column name. The formula shows an error such as
#REF!or#NAME?. Open the formula, retype the name using autocomplete, and confirm the table exists. - A duplicate header. Two columns with the same header make the reference ambiguous. Rename one header so each is unique.
- A deleted table. If you delete the table itself, formulas that use its name lose their target and return errors. Converting it back to a range is the safer option when you want to keep the data.
- Using the reference outside the spreadsheet. A structured reference only works inside the spreadsheet that holds the table. In an import from another file, you may need a normal range reference instead.
- Expecting filtered totals. As covered above,
SUM(Orders[Amount])totals all rows, not only the visible ones. - A mixed reference that stops growing. If you write
=SUM(Orders!C2:C4)you have a fixed range, even though the data lives in a table. Replace it withOrders[Amount]to get the growing behavior.
A short worked example
Suppose you have the three-row Orders table from the start of the tutorial. You want a small summary block outside the table, in cells F1:G3.
- In F1 type
Totaland in G1 enter=SUM(Orders[Amount]). The result is 855. - In F2 type
Paid ordersand in G2 enter=COUNTIF(Orders[Paid], TRUE). The result is 2. - In F3 type
Unpaid amountand in G3 enter=SUMIF(Orders[Paid], FALSE, Orders[Amount]). The result is 480. - Add a fourth row to the table: order 1004, Hooli, a date, an amount of 300, and Paid unchecked.
- Look at the summary again. Total is now 1155, Paid orders is still 2, and Unpaid amount is 780.
You did not edit a single formula. That is the behavior to rely on, and it is the main reason to prefer a named table over a fixed range for data that keeps growing.
Summary of the working model
- A table has a name, and the name works inside formulas anywhere in the spreadsheet.
TableName[ColumnName]refers to the body cells of one column.- Sheets resolves the reference every time it calculates, so the formula follows the table as it grows, moves, or is renamed.
- A filter hides rows from view but does not change what a structured reference covers.
- Clear, unique table names and column headers prevent most errors.
Exercise
A table named Orders has columns Customer, Amount, and Paid. Write one formula that returns the total Amount for rows where Paid is checked. Then explain what happens to the result when you add a new paid row at the bottom of the table.
Show answer
Use =SUMIF(Orders[Paid], TRUE, Orders[Amount]). The formula names the Paid column as the condition range and the Amount column as the sum range. When you add a new row to the table and check Paid, the table expands, the structured references cover the new row, and the total increases by the new amount. You do not need to edit the formula.
Exercise
A colleague wrote =SUM(Orders!D2:D50) to total the Amount column of a table. Give two reasons to replace it with =SUM(Orders[Amount]).
Show answer
First, the fixed range stops at row 50, so rows added past it are left out, while the structured reference always covers the whole column. Second, the address D2:D50 depends on where the column currently sits. If the table moves or columns are inserted, the address may no longer match, while the column name keeps pointing to the Amount data.