Array FunctionsIntermediate

Total a Customer's Spend Without a Helper Column Using SUMPRODUCT

When every order line has a quantity and a unit price, SUMIF cannot add up what a customer spent, because the money only exists once the two are multiplied. SUMPRODUCT multiplies and adds in one step, and comparisons inside it turn into the filter.

Task:

You do the books for a small coffee roaster that sells wholesale to cafés. This week's order book is in A2:E10: each line has the customer, the blend, the number of bags and the price per bag, which is lower on bigger orders. There is no line-total column, and the sheet is shared with the roastery floor, so you would rather not add one. In H3, work out how much the customer named in H2 spent this week. In H5, work out how much that same customer spent on the blend named in H4 alone. Both answers should update if someone types a different name into H2 or H4.

Interactive Spreadsheet

Hints

+5 XPno-hints bonus

Solve it on your own to keep the bonus. Each hint gets one step closer to the formula.

The data in this exercise

This is the grid you start with. Cell references in the task — B6, C2 — point at the row numbers and column letters below.

10 rows × 8 columns2 cells you fill in
ABCDEFGH
1OrderCustomerBlendBagsPrice per bag
21041Harbour CaféHouse Espresso1217.5CustomerHarbour Café
31042Millstone BakeryColombia Huila621Spend this week
41043Harbour CaféDecaf Swiss Water422.5BlendHouse Espresso
51044The Reading RoomHouse Espresso818.5Spend on that blend
61045Harbour CaféHouse Espresso1017.5
71046Millstone BakeryHouse Espresso518.5
81047The Reading RoomEthiopia Guji324
91048Harbour CaféEthiopia Guji224
101049Millstone BakeryDecaf Swiss Water322.5
What this exercise teachesMay contain the answer

SUMPRODUCT works through the ranges you give it in step, multiplying the values on each row and then adding up the row results, which is exactly what an order book with no line-total column needs: D2:D10*E2:E10 is the line total of every order, worked out in memory. The condition is folded in as one more factor. (B2:B10=H2) is a column of TRUE and FALSE, and arithmetic turns those into 1 and 0, so the rows for other customers are multiplied by zero and drop out. That leaves Harbour Café's four orders: 12 bags at 17.50, 4 at 22.50, 10 at 17.50 and 2 at 24.00, which is 523. The brackets around the comparison matter: without them the = would compare B2:B10 with the whole product that follows it rather than with H2. In H5 a second factor, (C2:C10=H4), switches off every row that is not House Espresso, and because the two factors are multiplied a row only counts when both are 1, which is how AND is written in arithmetic. Harbour Café's two espresso orders come to 210 plus 175, or 385. Note that 22 bags times the list price of 18.50 would have said 407: the volume discount is in the per-row prices, which is why the multiplication has to happen row by row and not on the totals. Pointing at H2 and H4 instead of typing the names into the formula is what lets the same cell answer for The Reading Room or for Ethiopia Guji the moment someone changes the name.