referencing pivot table cells with getpivotdata robert rosen

12
Referencing Pivot Table Cells with GetPivotData Robert Rosen

Upload: douglas-logan

Post on 18-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Referencing Pivot Table Cells with GetPivotData Robert Rosen

Referencing Pivot Table Cells with GetPivotData

Robert Rosen

Page 2: 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)

Data field name

Upper left cell of pivot table

Column field name

Column value

Page 3: Referencing Pivot Table Cells with GetPivotData Robert Rosen

• 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:

Page 4: Referencing Pivot Table Cells with GetPivotData Robert Rosen
Page 5: Referencing Pivot Table Cells with GetPivotData Robert Rosen

Why use GetPivotData?

Reason 1…

Page 6: Referencing Pivot Table Cells with GetPivotData Robert Rosen

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!

Page 7: Referencing Pivot Table Cells with GetPivotData Robert Rosen

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.

Page 8: Referencing Pivot Table Cells with GetPivotData Robert Rosen

Why use GetPivotData?

Reason 2…

Page 9: Referencing Pivot Table Cells with GetPivotData Robert Rosen

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 1OK

Week 2 + Week 2OK

Week 3 + Week 4..OOPS!

Page 10: Referencing Pivot Table Cells with GetPivotData Robert Rosen

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)

Page 11: Referencing Pivot Table Cells with GetPivotData Robert Rosen

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

Page 12: Referencing Pivot Table Cells with GetPivotData Robert Rosen

In Summary, GetPivotData References Can

• Adapt to changes in pivot table size/position• Avoid potential erroneous results when

referencing pivot tables with missing columns.