Confident CellsExcel practice Start free

GROUPBY and PIVOTBY: practice exercises

GROUPBY, PIVOTBY, PERCENTOF, sort biggest first, filter, subtotals: summaries as formulas. 8 exercises on real-looking data, each marked the moment you press Check. The first exercise is below to try now; the full lesson is part of Pro.

Your turn

In F2, use GROUPBY to show the total sales for each branch, with a Total at the bottom.

ABCDEFGHIJK
1BranchTeamQuarterSales (£)Sales by branch
2LoughboroughSupportQ4£40.00
3LincolnSupportQ2£75.00
4LoughboroughSupportQ3£50.00
5LincolnSupportQ2£205.00
6LeicesterFinanceQ4£300.00
7LoughboroughSupportQ4£170.00
8LincolnSalesQ2£230.00
9LoughboroughSupportQ2£110.00
10LincolnSalesQ1£215.00
11LeicesterSalesQ1£110.00
12LoughboroughSalesQ1£160.00
13LeicesterSalesQ3£305.00
14LoughboroughSupportQ4£135.00
15LoughboroughSupportQ1£300.00
16LeicesterFinanceQ4£250.00
17LeicesterSalesQ1£45.00
18LincolnFinanceQ2£135.00
19LeicesterSalesQ1£95.00

How it works

GROUPBY and PIVOTBY make a summary like a PivotTable's with a formula. You type it in one cell and the answer spills: each branch once, its total, and a Total row at the bottom.

=GROUPBY(A2:A8,C2:C8,SUM): what to group by, what to add up, and the function's name on its own, with no brackets. =PIVOTBY(A2:A8,B2:B8,C2:C8,SUM) puts a second field across the top. They're in Microsoft 365 and Excel for the web only.

=GROUPBY(A2:A8,C2:C8,SUM) =GROUPBY(A2:A8,C2:C8,SUM,,,-2) =GROUPBY(A2:A8,C2:C8,SUM,,,,B2:B8="Q1") =GROUPBY(A2:A8,C2:C8,PERCENTOF) =PIVOTBY(A2:A8,B2:B8,C2:C8,SUM)

Before you start: which Excel?

GROUPBY and PIVOTBY are new. They're in Microsoft 365 (the Excel that updates itself) and Excel for the web. The one-off versions you buy once, such as Excel 2024 or 2021, don't have them, and nor does anything older: they show #NAME? instead.

If your work uses an older Excel, make the same summary with a PivotTable (the first lessons in this section), or list each branch with UNIQUE and total it with SUMIFS. Check before you share a workbook: anyone opening it in an older Excel sees #NAME? too.

GROUPBY: a total for each branch

ABCDEFGH
1BranchQuarterSales (£)
2NottinghamQ1£120.00
3DerbyQ1£600.00
4LeicesterQ1£300.00
5NottinghamQ2£85.00
6DerbyQ2£280.00
7NottinghamQ2£240.00
8LeicesterQ2£155.00
  1. =GROUPBY(A2:A8,C2:C8,SUM) in E2. Nottingham's three sales are £120 + £85 + £240 = £445. GROUPBY does that for every branch, lists them A to Z, and adds a Total row: £1,780.
  2. =GROUPBY(A2:A8,C2:C8,AVERAGE) in E2. The third part is the function, as a name on its own: SUM, not SUM(). Swap it for AVERAGE, COUNT, MAX or MIN. Nottingham's average sale is £445 ÷ 3 = £148.33.

Biggest first, and only some rows

ABCDEFGH
1BranchQuarterSales (£)
2NottinghamQ1£120.00
3DerbyQ1£600.00
4LeicesterQ1£300.00
5NottinghamQ2£85.00
6DerbyQ2£280.00
7NottinghamQ2£240.00
8LeicesterQ2£155.00
  1. =GROUPBY(A2:A8,C2:C8,SUM,,,-2) in E2. The 6th part sorts. 2 means the 2nd column of the answer (the totals) and the minus puts the biggest first: Derby £880, Leicester £455, Nottingham £445. The two commas in a row skip parts 4 and 5.
  2. =GROUPBY(A2:A8,C2:C8,SUM,,,,B2:B8="Q1") in E2. The 7th part keeps only the rows where the test is TRUE, like FILTER. Just Q1: Derby £600, Leicester £300, Nottingham £120.

Shares with PERCENTOF

ABCDEFGH
1BranchQuarterSales (£)
2NottinghamQ1£120.00
3DerbyQ1£600.00
4LeicesterQ1£300.00
5NottinghamQ2£85.00
6DerbyQ2£280.00
7NottinghamQ2£240.00
8LeicesterQ2£155.00
  1. =GROUPBY(A2:A8,C2:C8,PERCENTOF) in E2. PERCENTOF gives each branch's share of all the sales: Nottingham's £445 out of £1,780 is 25%. The Total is 100%. Format the column as a percentage.

PIVOTBY: a second field across the top

ABCDEFGH
1BranchQuarterSales (£)
2NottinghamQ1£120.00
3DerbyQ1£600.00
4LeicesterQ1£300.00
5NottinghamQ2£85.00
6DerbyQ2£280.00
7NottinghamQ2£240.00
8LeicesterQ2£155.00
  1. =PIVOTBY(A2:A8,B2:B8,C2:C8,SUM) in E2. The branches go down the side, the quarters across the top, and each sale is added in where they meet. Nottingham in Q2 is £85 + £240 = £325. There's a Total row and a Total column.

Formula or PivotTable?

Both give the same numbers. Pick by what you need:

  • A formula (GROUPBY or PIVOTBY) updates by itself when the data changes, with no Refresh. It can feed other formulas, and it's easy to copy into another workbook.
  • A PivotTable lets you drag fields about to try different views, filter with slicers, group dates into months and quarters, and draw a PivotChart. It also works in older Excel.

One catch: GROUPBY sorts text A to Z, so months typed as words come out Apr, Aug, Dec…. Use quarters, month numbers or a PivotTable, which knows the calendar order.

What you'll practise

  1. In F2, use GROUPBY to show the total sales for each branch, with a Total at the bottom.
  2. In F2, show the average sale for each team.
  3. In F2, show how many sales each branch made (not how much they came to).
  4. In F2, show the total sales for each branch with the biggest total first.
  5. In F2, show the total sales for each branch, counting only the quarter in G1. Use G1, not the quarter typed in, so the summary changes when G1 does.
  6. In F2, show each branch's share of all the sales, as a percentage, using PERCENTOF.
  7. In F2, use PIVOTBY to show total sales with the branches down the side and the quarters across the top.
  8. In F2, show total sales for each team within each branch, with a subtotal for each branch. (Give GROUPBY two columns to group by.)

Guide with worked examples: GROUPBY and PIVOTBY: summaries without a PivotTable