Sub topic 16
Building summary tables with mixed references and Excel tables
This chapter assumes you can enter and copy formulas, you know the difference between relative and absolute references, and you have already written SUMIFS, COUNTIFS, and AVERAGEIFS formulas with a single criterion or a few criteria. The goal is to write one formula and copy it across a whole grid of results. You will do this with mixed references first, then with an Excel table.
Why one formula should fill a whole grid
Suppose you want total Amount for every combination of Region and Product. You could type a separate SUMIFS into each cell and hard-code "West" and "Laptop" inside it. That works, but it has three problems:
- Each formula differs from its neighbors, so errors are hard to spot.
- Adding a new region means writing new formulas by hand.
- Changing a label in the grid does not change the result.
A better design puts the criteria in the grid's headers and has every cell read them. Then one formula, copied to every cell, produces the whole table. The copy only works if each reference moves or stays fixed in the right way.
The sample data
The examples use the sales layout from earlier chapters. Headers are in row 1 and data runs from row 2 to row 100.
A: Date B: Region C: Product D: Amount E: Notes
2025-01-05 West Laptop 1200
2025-01-09 East Monitor 300 Backorder
2025-02-02 West Monitor 310
2025-02-14 North Laptop 1150 GiftThe summary grid goes to the right of the data. Region names go down column G, starting in G2. Product names go across row 1, starting in H1.
| Cell | Content |
|---|---|
| G1 | blank, or a label such as Region |
| H1 | Laptop |
| I1 | Monitor |
| G2 | West |
| G3 | East |
| G4 | North |
Mixed references
A reference such as $G2 is a mixed reference. The $ locks the part that follows it. In $G2, the column G is locked and the row 2 is free to change. In H$1, the column H is free to change and the row 1 is locked. In $D$2:$D$100, both parts are locked, so the range never moves.
When you copy a formula, Excel shifts every unlocked part by the same distance as the copy. Copying one cell to the right adds one column to each unlocked column letter. Copying one cell down adds one to each unlocked row number.
For the grid, each cell needs these rules:
- The data ranges (
D2:D100,B2:B100,C2:C100) must never move, so lock them fully. - The Region criterion must always come from column G, but the row must follow the cell's own row. Use
$G2. - The Product criterion must always come from row 1, but the column must follow the cell's own column. Use
H$1.
Put this formula in H2:
=SUMIFS($D$2:$D$100, $B$2:$B$100, $G2, $C$2:$C$100, H$1)Copy H2 across to I2 and down to H4:I4. In I3, for example, Excel rewrites the formula as:
=SUMIFS($D$2:$D$100, $B$2:$B$100, $G3, $C$2:$C$100, I$1)The data ranges are unchanged. The Region reference moved down one row to $G3. The Product reference moved right one column to I$1.
The F2 key cycles through reference types while the cursor is on a reference. Each press goes from H1 to $H$1, then H$1, then $H1, then back to H1.
Using the same pattern with COUNTIFS and AVERAGEIFS
The same grid layout works for the other two functions. Only the function name and the first argument change.
For counts, there is no sum range, so the formula starts with the first range and criterion pair:
=COUNTIFS($B$2:$B$100, $G2, $C$2:$C$100, H$1)For averages, the range to average comes first, as with SUMIFS. Wrap it in IFERROR so empty combinations do not show #DIV/0!:
=IFERROR(AVERAGEIFS($D$2:$D$100, $B$2:$B$100, $G2, $C$2:$C$100, H$1), "No sales")In the sample data, North has no Monitor rows. The SUMIFS grid shows 0 for that cell, the COUNTIFS grid shows 0, and the AVERAGEIFS grid shows "No sales".
Adding row and column totals
A grid usually needs totals. You can sum the grid cells, or you can write a SUMIFS that omits one criterion. For a grand total by region in column J, leave the product pair out:
=SUMIFS($D$2:$D$100, $B$2:$B$100, $G2)This is better than adding H2:I2 when the data contains a product that is not in your header row. The omitted-criterion version counts every row for that region. The sum of the grid cells counts only the products you listed. If the two numbers differ, a product is missing from the headers or is spelled differently in the data.
Excel tables and structured references
Fixed ranges such as $D$2:$D$100 have a weakness. If the data grows to row 150, the formulas ignore rows 101 to 150. If you make the range far larger to be safe, you can pick up stray totals or notes below the data.
An Excel table solves this. To create one, click any cell in the data and press Ctrl+T, then confirm that the table has headers. Name it Sales on the Table Design tab. A table has these properties:
- It expands automatically when you type in the row below it.
- Each column has a name taken from its header.
- Formulas can refer to a whole column by name.
With the table named Sales, the earlier West total becomes:
=SUMIFS(Sales[Amount], Sales[Region], "West")Sales[Amount] means the Amount column of the Sales table, whatever its current size. New rows are included without editing the formula.
The summary grid can use structured references too:
=SUMIFS(Sales[Amount], Sales[Region], $G2, Sales[Product], H$1)Here the table column references do not need $, because they always refer to the full column. The $G2 and H$1 criteria cells still need mixed references, since they are ordinary cells that must move correctly when you copy.
Things to watch with tables
- Column names that contain spaces or special characters work in the formula bar, but certain characters need an apostrophe escape. Keep header names short and plain to avoid this.
- If you rename a header, Excel updates formulas that use it. If you delete the column, those formulas show
#REF!. - A table cannot have blank header cells or two columns with the same name.
- Structured references and a fixed A1 range cannot be mixed in a way that makes the ranges different sizes. Every range in one SUMIFS must have the same number of rows, or the result is
#VALUE!.
Choosing between fixed ranges and tables
| Situation | Better choice |
|---|---|
| Data is a fixed snapshot and will not grow | Fixed ranges with `$` |
| Rows are added regularly | Excel table with structured references |
| You share the file with people who read formulas | Table, because `Sales[Region]` is readable |
| You need compatibility with very old tools that cannot read tables | Fixed ranges |
Common mistakes
- Locking the wrong part. Writing
$G$2for the region criterion makes every cell read G2, so every row of the grid shows the West results. WritingG$2makes every row read row 2. - Forgetting to lock the data ranges. With
D2:D100unlocked, copying the formula down moves the range toD3:D101, thenD4:D102. Totals drift and the last rows are dropped without any error message. - Header text that does not match the data. A header of "Laptops" will not match the product "Laptop". Trailing spaces cause the same problem. The result is 0, not an error.
- Numbers stored as text. If a header holds the text "2025" but the data holds the number 2025, matching can fail in surprising ways. Check alignment and use the same type on both sides.
- Blank header cell. A blank criteria cell is treated as 0, not as "any value", so the formula usually returns 0.
Exercise
A summary grid has regions in G2:G4 and products in H1:J1. Write the formula for H2 that totals Amount (D2:D100) using Region (B2:B100) and Product (C2:C100), so that it can be copied to all of H2:J4 without edits. Then say what H$1 becomes after copying to J4.
Show answer
=SUMIFS($D$2:$D$100, $B$2:$B$100, $G2, $C$2:$C$100, H$1). After copying to J4, the product reference becomes J$1 because the column is free to move and the row is locked. The region reference becomes $G4.
Exercise
The data is in a table named Sales with columns Region, Product, and Amount. Write a formula that counts the rows for the region in G2 and the product in H1 and can be copied across and down a grid. Why does it not need $ on the table columns?
Show answer
=COUNTIFS(Sales[Region], $G2, Sales[Product], H$1). Structured references such as Sales[Region] always point to the whole column of the table, and they do not shift when the formula is copied. Only the criteria cells, which are ordinary cell references, need mixed references.
Exercise
A grid built with the formula =SUMIFS(D2:D100, B2:B100, $G2, C2:C100, H$1) gives correct values in row 2 but wrong values below. What is the cause, and what is the fix?
Show answer
The data ranges are not locked, so copying down shifts them (row 3 uses D3:D101, B3:B101, and C3:C101). Lock them with $, giving $D$2:$D$100, $B$2:$B$100, and $C$2:$C$100. Alternatively, use Sales[Amount], Sales[Region], and Sales[Product] with a table.