Sub topic 14
Pulling pivot results into formulas with GETPIVOTDATA
This chapter assumes you can build a pivot table with Region in Rows and a summed Revenue in Values. You should also be comfortable writing a basic formula with cell references. Here you will read a single number out of a pivot table with GETPIVOTDATA, make the formula dynamic, and handle the errors it raises.
Why not just click the cell?
Suppose a pivot table sits on a sheet named Pivot with its top-left cell at A1. The West total is in B4. You could write =Pivot!B4 in a report, and it works until the pivot changes. If a new region appears and sorts above West, the pivot table redraws and B4 now holds a different region's total. Your report shows the wrong number and gives no error.
GETPIVOTDATA fixes this by asking for the value by name ("Revenue for Region = West") and not by position. The pivot table can resize, re-sort, or gain rows, and the formula still finds the right cell.
The syntax
=GETPIVOTDATA(value_name, any_pivot_table_cell, [original_column, pivot_item, ...])value_nameis the value field you want, as text. In the simplest case this is the source column name, such as"Revenue". Sheets also recognizes the label shown in the pivot header, such as"SUM of Revenue". If you use the same column twice with different summaries (for example, a sum and an average), use the displayed header text to say which one you mean.any_pivot_table_cellis a reference to any cell inside the pivot table. Its only job is to say which pivot table you mean. Point it atA1, or at any cell you like, as long as it is inside the table.original_column, pivot_itempairs narrow the result. Each pair names a field you placed in Rows or Columns, and the item within it that you want.
Here is the formula from the opening example:
=GETPIVOTDATA("Revenue", Pivot!A1, "Region", "West")It returns the Revenue summary for the West row of the pivot table that contains Pivot!A1. The pivot table can move to a different position later and the formula still works, provided the reference points inside the table.
Letting Sheets write the formula for you
You do not have to type this by hand. Type = in a cell, then click a value cell inside a pivot table. Sheets inserts a GETPIVOTDATA formula with the correct field and item pairs instead of a plain cell reference such as Pivot!B4.
This is often what you want, but a plain reference sometimes appears instead. If so, check that you clicked a value cell and not a header. Also check that your Sheets settings haven't changed the default behavior. When the generated formula contains hard-coded text like "West", you can replace that text with a cell reference, as the next section shows.
Making the formula dynamic
Hard-coded item names mean you edit the formula whenever the question changes. Replace them with cell references so one formula can fill a whole report.
Suppose A2:A4 hold region names typed in a report table, and the pivot table is on the Pivot sheet:
=GETPIVOTDATA("Revenue", Pivot!$A$1, "Region", $A2)The $A$1 anchor keeps the pivot reference fixed as you fill down. $A2 changes with each row, so every row asks for its own region.
You can combine two fields when the pivot has both Region in Rows and Product in Columns:
=GETPIVOTDATA("Revenue", Pivot!$A$1, "Region", $A2, "Product", B$1)Here B$1 holds a product name in a header row of your report. The pairs combine with AND logic: the formula returns the intersection of West and the chosen product.
Totals and subtotals
The number of pairs you supply controls which level of the pivot table you read.
| Pairs supplied | What you get |
|---|---|
| None | The grand total for that value |
| One field in Rows | The row total for that item (for example, one region across all products) |
| Fields from both Rows and Columns | A single intersection cell |
For example, this returns the grand total:
=GETPIVOTDATA("Revenue", Pivot!A1)This only works if grand totals are visible in the pivot table. If you turn off the Rows or Columns totals in the editor (see the chapter on sorting and totals), the cells that GETPIVOTDATA would read no longer exist, and the formula returns #REF!.
Why `#REF!` appears
GETPIVOTDATA returns #REF! whenever no cell matches your request. The usual causes are:
- The item is not in the pivot table. A typo such as
"Wset"has no match. A region hidden by a pivot filter also has no match, even though it exists in the source data. - The field is not in Rows or Columns. You cannot ask for
"Product"if Product is only in Filters. - The reference cell is outside the pivot table. Check that
any_pivot_table_celllies inside the pivot's current output range. - The value name does not match. If you renamed the value or summarized the same column twice, use the exact label shown in the pivot header.
- Totals are turned off and you asked for a total, as described above.
- Item type mismatch. If an item is a number or a date, the pair must pass a real number or date, not a text lookalike. A cell showing
2026as text will not match the number2026.
Be careful with IFERROR. Wrapping the formula in IFERROR(..., 0) hides a real missing item behind a believable zero. A safer pattern returns a visible marker, so a missing item stands out:
=IFERROR(GETPIVOTDATA("Revenue", Pivot!$A$1, "Region", $A2), "not in pivot")If a region is legitimately absent from the pivot table because it has no sales, you can decide deliberately to show 0 instead. Make that choice for each report, not as a blanket default.
Filters and date groups
GETPIVOTDATA reads what the pivot table currently displays, so it follows the pivot's filters. If you filter the pivot table to exclude the East region, every formula that asks for East returns #REF!, and the grand total shrinks accordingly. That is correct behavior, but it surprises people who built a report on top of an unfiltered pivot and then let someone else apply a filter.
Date groups need extra care. When you group dates by year or month in the pivot table, the items are group labels such as 2026 or Jan, not the original dates. The pair has to match the label the pivot shows, using the matching type (a number for a year group, text for a month name). If a date pair fails, look at how the pivot header actually displays the item and copy that form.
Cross-checking against the source data
Because GETPIVOTDATA reads the pivot table's output, it inherits any problem in the pivot's setup: a stale source range, a filter, or a summarization other than the one you assumed. A direct formula against the source data gives you an independent check:
=SUMIFS(Sales!E:E, Sales!B:B, "West")If this and GETPIVOTDATA disagree, one of them is reading different rows. Typical reasons are a pivot filter, a source range that stops before the newest rows, or a Summarize by of COUNT where you assumed SUM. The final chapters on formula alternatives and troubleshooting cover these causes in more detail. A workable habit is to put both formulas side by side in a report and add a third cell that flags a mismatch:
=IF(ROUND(B2 - C2, 2) = 0, "OK", "CHECK")Here B2 holds the GETPIVOTDATA result and C2 holds the SUMIFS result. Rounding avoids false alarms from floating-point noise in decimal sums.
When to choose something else
GETPIVOTDATA is a lookup into an existing pivot table. It does not compute anything the pivot table does not already show. Consider the alternatives in these cases:
- You only need one number and no pivot table.
SUMIFSreads the source data directly and has no dependency on pivot layout or filters. - You want a formula-driven summary table.
QUERYproduces a grouped result that you control entirely in a formula, so no one can change it by dragging fields in the editor. - Your pivot table already shows the layout you need. Use
GETPIVOTDATAto feed those results into a dashboard, a chart's source range, or a calculation elsewhere.
Exercise
A pivot table on the sheet Pivot starts at A1, with Region in Rows, Product in Columns, and a summed Revenue in Values. Product is also used in a filter that currently hides "Gadgets". You write =GETPIVOTDATA("Revenue", Pivot!$A$1, "Region", "West", "Product", "Gadgets") and get #REF!. Name two different fixes, and say what the plain =SUMIFS version would have returned.
Show answer
The filter hides the Gadgets item, so no pivot cell matches the pair. Fix 1: remove or adjust the filter so Gadgets is shown, and the formula then returns the West/Gadgets revenue. Fix 2: read the value from the source data with SUMIFS instead, which ignores the pivot filter. The SUMIFS version, =SUMIFS(Sales!E:E, Sales!B:B, "West", Sales!C:C, "Gadgets"), would have returned the real West/Gadgets revenue because it never looks at the pivot table. Wrapping the formula in IFERROR(..., 0) would hide the problem and report zero, which is wrong here.
Exercise
You have a report with region names in A2:A10 and want each row in B to show that region's revenue from the pivot table at Pivot!A1. Write the formula for B2 so it can be filled down, and explain why the pivot reference uses dollar signs but the region reference does not.
Show answer
=GETPIVOTDATA("Revenue", Pivot!$A$1, "Region", $A2). The pivot reference is anchored with $A$1 so it still points into the same pivot table in every row after filling down. The region reference $A2 has a fixed column but a relative row, so each filled row picks up its own region name from column A.