Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a reference for GetPivotData's Data_Field argument?

Tags:

excel-2007

I'm trying to use GetPivotData to query "Foo Bar" values from a pivot table. Just by typing = in a cell and clicking on the pivot table does most of the legwork, as Excel writes most of the formula. For example I get:

=GETPIVOTDATA("Foo Bar", 'Pivot Table'!D1, "Day", DAY(2010,10,10))       → 42

I need to have the first and last argument referenced to other cells and some extra dollars. I tried:

=GETPIVOTDATA($A$1, 'Pivot Table'!$D$1, "Day", $C3)                       → #REF!

...where A1 contains Foo bar and C3 contains =DAY(2010,10,10).

This obviously gives a nice #REF!. Hardcoding the field name in the formula instead gives the correct value instead:

=GETPIVOTDATA("Foo Bar", 'Pivot Table'!$D$1, "Day", $C3)                 → 42

Is this an undocumented shortcoming of the function (all examples use an hardcoded field name, but nowhere is mentioned I can't use references for the first argument) or am I doing something wrong?

like image 652
badp Avatar asked Sep 19 '10 13:09

badp


1 Answers

To fix this problem, you can concatenate an empty string ( "" ) at the end of the cell reference:

=GETPIVOTDATA(B10 & "" ,$B$3,"Region",A11)`

from http://www.contextures.com/xlpivot06.html

like image 195
user642236 Avatar answered Nov 23 '22 18:11

user642236