120 likes | 236 Views
Referencing Pivot Table Cells with GetPivotData. Robert Rosen. GetPivotData example. A reference to the Grand Total value in game 2 in this pivot table would be:. =GETPIVOTDATA(“Yds",$A$1,“Game", 2 ). Upper left cell of pivot table. Data field name. Column field name. Column value.
E N D
Referencing Pivot Table Cells with GetPivotData Robert Rosen
GetPivotData example A reference to the Grand Total value in game 2 in this pivot table would be: =GETPIVOTDATA(“Yds",$A$1,“Game",2) Upper left cell of pivot table Data field name Column field name Column value
By default, clicking on a pivot table cell while entering a formula will insert a GetPivotData reference into the formula instead of a regular cell reference. • You can change this behavior in Excel options:
Why use GetPivotData? Reason 1…
Suppose a data refresh adds 4 new rows to our pivot table A regular cell reference to a cell in the grand total row (formerly row 13, now row 17) won’t show the Grand Total any longer… but a GetPivotData reference will!
Note: In Our Previous Example… =GETPIVOTDATA("Yds",$R$197,"week",2) If you drag this reference one cell to the right to reference the value for fiscal month 3, the formula is not changed automatically. You have to manually change the 2 to 3.
Why use GetPivotData? Reason 2…
Suppose we want to add the values from these 2 tables for each week in 2 different years No data in the data source for this table for week 3 – Excel omits the column Sum of column values across tables is: Week 1 + Week 1 OK Week 2 + Week 2 OK Week 3 + Week 4 ..OOPS!
If week 3 is in column F and table #2 starts at row 12, we could say instead: • =GETPIVOTDATA("Yds",$A$1,"week",3) + GETPIVOTDATA("Yds",$A$15,"week",3) • Will produce a #REF! error (since the second GETPIVOTDATA reference is to something that doesn’t exist – a week 3 column in the second table)
The improved version: • =IFERROR(GETPIVOTDATA("Yds",$A$1,"week",3) + GETPIVOTDATA("Yds",$A$15,"week",3), GETPIVOTDATA("Yds",$A$1,"week",3) ) • i.e. if week 3 value in table 2 is missing, result is just the value in table 1 • The IFERROR function takes two arguments: • The value to show if evaluating it doesn’t produce an error • The value to show otherwise
In Summary, GetPivotData References Can • Adapt to changes in pivot table size/position • Avoid potential erroneous results when referencing pivot tables with missing columns.