Sub topic 16
Building summary tables with mixed references and Excel tables
This chapter assumes you can enter and copy formulas, know the difference between relative and absolute references, and have used SUMIFS on a header-and-rows data set. The goal is one formula that you write once and copy across and down a whole summary grid.
The problem with copying criteria
A summary grid lists regions down the side and products across the top. Each cell needs the total for one region and one product. Typing a separate SUMIFS into every cell is slow, and a change to the criteria means editing every cell. A single formula that copies correctly avoids both problems.
The sales data from earlier chapters sits in A1:E100. Put the regions in G2:G4 and the products in H1:J1.
| Row | G | H | I | J |
|---|---|---|---|---|
| 1 | Laptop | Monitor | Dock | |
| 2 | West | |||
| 3 | East | |||
| 4 | North |
Lock the data, mix the criteria
Each part of the formula needs a different kind of anchor:
- The sum range and the criteria ranges must never move, so they are fully absolute:
$D$2:$D$100. - The region criterion must stay in column G but follow the row, so it is
$G2. - The product criterion must stay in row 1 but follow the column, so it is
H$1.
=SUMIFS($D$2:$D$100, $B$2:$B$100, $G2, $C$2:$C$100, H$1)Enter this in H2, then copy it to H2:J4. In I3, for example, Excel adjusts it to use $G3 and I$1. The data ranges stay fixed.
Use an Excel table so ranges grow
Fixed ranges such as $D$2:$D$100 stop at row 100. Rows added below it are ignored without any warning. To avoid this, convert the data to a table. Click inside the data and press Ctrl+T, then name the table Sales on the Table Design tab.
Structured references use the table and column names, and they expand automatically as rows are added:
=SUMIFS(Sales[Amount], Sales[Region], "West")You can use them in the grid too. Here the criteria cells keep their mixed anchors:
=SUMIFS(Sales[Amount], Sales[Region], $G2, Sales[Product], H$1)Structured references are always locked to their column, so they need no dollar signs. Only the criteria cells still need mixed references.
Common mistakes
- Missing
$on a data range. The range drifts as you copy, and totals shrink or become wrong. Check by selecting a far-away cell and reading its formula. - Wrong anchor on a criteria cell. Writing
G2instead of$G2makes the region reference slide right to column H, which holds a product name. The result is usually zero. - Labels that do not match the data. A trailing space in a header cell or in the data returns zero. Retype the label, or compare it with
=LEN(G2).
Exercise
The East and Dock totals are in cell J3. Your grid formula in H2 is =SUMIFS($D$2:$D$100, $B$2:$B$100, G2, $C$2:$C$100, H$1). What does the formula in J3 look up for region, and what fix does it need?
Show answer
It looks up K3, because the region reference G2 has no column lock and shifts two columns right when copied. K3 is empty, so the total is zero. Change G2 to $G2 in H2 and copy the formula again.
Exercise
Why does =SUMIFS(Sales[Amount], Sales[Region], $G2, Sales[Product], H$1) keep working after you add 20 new rows to the Sales table?
Show answer
Structured references cover the whole table column, and the table grows to include new rows. A fixed range ending at row 100 would not.