PivotTables: report from a PivotTable: practice exercises
GETPIVOTDATA: type = and click a number, fields and items, totals, a cell in place of a name, Generate GetPivotData on and off, #REF!, a summary sheet. 8 exercises on real-looking data, each checked as you go. The full lesson is part of Pro.
This lesson has a PivotTable builder like Excel's: drag fields into Rows, Columns and Values, and each task is checked as you go.
How it works
Type = in a cell and click a number in a PivotTable, and Excel writes GETPIVOTDATA for you: =GETPIVOTDATA("Sales",$E$1,"Branch","Leeds"). It reads Leeds's sales by name, so it still finds them after the PivotTable is sorted, filtered or moved.
That makes it the way to build a summary or report from a PivotTable. When you want a plain reference you can fill down, such as =F2*20%, turn off Generate GetPivotData: PivotTable Analyse (Pivot Table Analyse on a Mac), Options ▾.
=GETPIVOTDATA("Sales",$E$1,"Branch","Leeds") =GETPIVOTDATA("Sales",$E$1) =GETPIVOTDATA("Sales",$E$1,"Branch",H2) =IFERROR(GETPIVOTDATA("Sales",$E$1,"Branch","Leeds"),0)
Read a number from a PivotTable
The PivotTable shows Leeds sold £12,400. Type = in another cell and click that number, and Excel writes:
=GETPIVOTDATA("Sales",$A$3,"Branch","Leeds"), which gives 12,400.
| Row Labels | Sum of Sales |
| Derby | 10800 |
| Leeds | 12400 |
| York | 9650 |
| Grand Total | 32850 |
- "Sales": the value to read (Sum of Sales).
- $A$3: the PivotTable's top-left cell. Any cell in the PivotTable would do.
- "Branch","Leeds": which number: the branch that's Leeds.
Sort the PivotTable, add a branch or move it, and the formula still finds Leeds. A plain =B5 shows whatever lands in B5. In Excel, choose New Worksheet in Create PivotTable so each PivotTable has a sheet of its own, starting at A3. Here it sits beside the data at E1, so you'll see $E$1.
Fields, items and totals
Leeds sold £4,300 in February: =GETPIVOTDATA("Sales",$A$3,"Branch","Leeds","Month","Feb"). Each field in Rows or Columns gets a pair: its name, then its item.
Leave a pair out and you get the total over it. Without Month, it's Leeds for every month: £12,400. With no pairs at all, =GETPIVOTDATA("Sales",$A$3), it's the Grand Total: £32,850.
A cell can stand in for a name. With Leeds in H2, =GETPIVOTDATA("Sales",$A$3,"Branch",H2) gives £12,400, and filled down it reads H3, H4 and so on. That's how to fill in a list.
#REF!, and turning it off
GETPIVOTDATA only reads what the PivotTable shows. Untick York, turn the Grand Total off, or ask for a field that isn't in it, and you get #REF!. =IFERROR(GETPIVOTDATA(…),0) shows 0 instead.
Sometimes you want plain references: VAT beside each branch, =B4*20%, filled down. GETPIVOTDATA names one branch, so filling it down repeats that branch. Turn it off: PivotTable Analyse, the ▾ by Options, untick Generate GetPivotData. Then = and a click writes B4, as for any cell. It stays off until you turn it back on.
A one-page summary
A report that says "Leeds: £12,400" and "February, all branches: £21,700" can read every number from a PivotTable with GETPIVOTDATA.
- Make the PivotTable on its own sheet (New Worksheet).
- On a Summary sheet, type the labels, then each number as = and a click on the PivotTable sheet:
=GETPIVOTDATA("Sales",Pivot!$A$3,"Month","Feb"). - When the data changes, Refresh the PivotTable, and the summary follows.
What you'll practise
- In I2, show Leeds's total sales by reading it from the PivotTable: type = in I2, click Leeds's total in the PivotTable, then press Enter. Excel writes the GETPIVOTDATA formula for you.
- Type a GETPIVOTDATA formula in I2 for the sales of all the branches together: =GETPIVOTDATA("Sales",$E$1). With no field and item after $E$1, it gives the Grand Total.
- In L3, show what York sold in Oct: type =, click the cell where York meets Oct in the PivotTable, then Enter.
- Fill in the sales for the three branches listed in H2:H4. In I2, write a GETPIVOTDATA that uses H2 for the branch, in place of its name in quotes: =GETPIVOTDATA("Sales",$E$1,"Branch",H2). Then fill it down to I4.
- Work out 20% VAT on each branch's sales in G2:G5, beside the PivotTable. A formula to fill down needs a plain reference, so first turn off Generate GetPivotData (PivotTable Analyse, Options ▾). Then type = in G2, click F2, type *20%, press Enter, and fill down to G5.
- I2 should show Nottingham's sales. It was typed as =F4, but the PivotTable has since been sorted biggest first, so F4 now holds another branch's. Rewrite I2 so it finds Nottingham wherever it is: type =, click Nottingham's total, Enter.
- Leicester has been unticked in the PivotTable, so I2 shows #REF!: GETPIVOTDATA can only read what the PivotTable shows. Keep Leicester hidden, and wrap I2's formula in IFERROR so it shows 0 instead: =IFERROR(GETPIVOTDATA("Sales",$E$1,"Branch","Leicester"),0).
- Fill in the summary from the PivotTable, with GETPIVOTDATA: in L2, the sales of all branches in Oct (the Grand Total under Oct); in L3, Leeds's sales for all the months (the Grand Total beside Leeds).