Sub topic 9
Calculated Columns
A calculated column is a table column where one formula applies to every row. You enter the formula once, and Excel fills it into the whole column. This chapter assumes you can create and name a table and that you have seen structured references such as SalesTable[Amount].
How a calculated column works
Suppose SalesTable has the columns Quantity, Unit Price and a new empty column named Line Total. Select the first empty cell under the Line Total header and type this formula:
=[@Quantity]*[@[Unit Price]]When you press Enter, Excel fills the formula down the entire column. It does this for existing rows and for rows you add later. The @ symbol means "this row", so each cell multiplies the Quantity and Unit Price from its own row.
Column names that contain spaces or special characters need an extra pair of brackets, as in [@[Unit Price]]. Excel adds these for you if you build the formula by clicking cells instead of typing.
Why use them
- Consistency. Every row holds the same formula, so one row cannot quietly differ from the others.
- Readable formulas.
[@Quantity]*[@[Unit Price]]is easier to read than=B2*C2. - Automatic growth. A new row gets the formula without any copying or dragging.
- Easy edits. If you change the formula in one cell, Excel rewrites the rest of the column to match.
Using the column elsewhere
Once the column exists, you can total it from outside the table with a structured reference:
=SUM(SalesTable[Amount])This sum covers every row in the Amount column and grows as the table grows. For a column of your own, replace Amount with its header name, such as SalesTable[Line Total].
Common errors and surprises
Exceptions in the column
If you type a different formula or a constant value into one cell of a calculated column, that cell becomes an exception. Excel marks it with a small green triangle in the corner. Exceptions are not overwritten when you edit the column formula, so a total can end up wrong without any warning. Delete the stray value, or retype the column formula in that cell, to remove the exception.
Auto-fill does not happen
If the formula stays in one cell, the AutoCorrect option "Fill formulas in tables to create calculated columns" is probably off. Open File, then Options, then Proofing, then AutoCorrect Options, then the AutoFormat As You Type tab, and turn it on. After a fill, a small AutoCorrect button appears next to the cells. You can use it to undo the fill for that one action.
Clicking cells gives A1 references
Excel's default is to produce structured references when you click cells inside a table. If you see =B2*C2 instead, the option "Use table names in formulas" is turned off. You can find it in File, Options, Formulas.
Formulas on the wrong side of the header
A formula in a cell outside the table, even directly next to it, is not part of the table and does not fill down. Table columns must sit inside the table's boundaries.
Quick checklist
- Type the formula in the first cell of an empty column inside the table.
- Press Enter and confirm that every row filled.
- Look for green-triangle exceptions in the column.
- Add a test row below the table and confirm that the formula appears in it.
Exercise
A table named OrdersTable has the columns Qty and Price. You type =[@Qty]*[@Price] in a new column, but only that one cell gets the formula and the rest stay empty. Name one setting you should check, and say how you would confirm that the fix worked.
Show answer
Check that the AutoCorrect option "Fill formulas in tables to create calculated columns" is enabled (File, Options, Proofing, AutoCorrect Options, AutoFormat As You Type). After enabling it, re-enter the formula. Confirm the fix by checking that every row now shows the formula, and by adding a new row below the table and seeing that it receives the formula as well.
Exercise
In a calculated column of 500 rows, you overtype one cell with the number 0. Later you change the column formula. What happens to that cell, and how can you spot it?
Show answer
The cell becomes an exception and keeps the value 0, because the edit to the column formula does not overwrite it. It is marked with a green triangle in the corner of the cell. Retyping the column formula in that cell restores it.