Adjusting GETPIVOTDATA Formula To Be Dynamic

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
351
Office Version
  1. 2019
Platform
  1. Windows
I am on the Year To Date (YTD tab now, and stuck on the same thing When I grab the static formula for the Pivot Table position, I need to adjust the Org # portion so the formula can be pulled downward and will translate properly to the diffferent Org #'s, and same holds true for date needing to be able to be pulled to right, as well as account for the fact that next year will be a new year. I'm trying very hard, but I'm having a tough time trying to grasp certain aspects of the GETPIVOTDATA function. Any help here greatly appreciated as always.

Green/White table w/ blacked out names: this table (named "YTD_GS") is the main sheet where the GETPIVOTDATA formulas go. Sheet name is "Main".
Black/white Pivot Table:

If I just grab the static Power Pivot data cell, the formula looks like this: =GETPIVOTDATA("[Measures].[Sum of Line Item Total]",'YTD GS'!$B$3,"[Monthly Orders Reports].[Org #]","[Monthly Orders Reports].[Org #].&[237]","[Monthly Orders Reports].[Date (Year)]","[Monthly Orders Reports].[Date (Year)].&[2021]")
And it fills down incorrectly like this.
1617511134110.png

.
1617511387388.png

I tried editing it myself and came up with this, which seems right to me, but it only throws #REF errors.
=GETPIVOTDATA("[Measures].[Sum of Line Item Total]",'YTD GS'!$B$3,"[Monthly Orders Reports].[Org #]","[Monthly Orders Reports].[Org #].&["&[@[Org '#]]&"]","[Monthly Orders Reports].[Date (Year)]","[Monthly Orders Reports].[Date (Month)].&["&TEXT(TODAY()-1,"mmm")&"]")

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Your Org # lookup looks fine but I don't understand where you get the reference to Date(Month) from.
How did you get from this
"[Monthly Orders Reports].[Date (Year)]","[Monthly Orders Reports].[Date (Year)].&[2021]"
to
"[Monthly Orders Reports].[Date (Year)]","[Monthly Orders Reports].[Date (Month)].&["&TEXT(TODAY()-1,"mmm")&"]"
 
Upvote 0
Just borrowing from another formula given to me which actually did work. Again, I'm really new to Pivot Tables and don't yet fully understand the GETPIVOTDATA formula. This is an area where I'm not sure, so I tried borrowing from helpful people on this site such as yourself. There was no logic in my decision to use that except for the fact that as a final ditch effort on my part to try and make it work,I decided to try using a piece from another formula which did in fact solve that same problem. You are just seeing my most recent effort to make the formula work correctly.
 
Upvote 0
If you are happy to have the 2021 hard coded then can you try this ?
I don't have your model and on a mobile at the moment

=GETPIVOTDATA("[Measures].[Sum of Line Item Total]",'YTD GS'!$B$3,"[Monthly Orders Reports].[Org #]",[@[Org '#]],"[Monthly Orders Reports].[Date (Year)]","[Monthly Orders Reports].[Date (Year)].&[2021]")
 
Upvote 0
No, that's the problem. I need both Org # and Date to not be hard coded. That's what I'm having trouble doing.
 
Upvote 0
Your pIvot is only showing a Year field and your results table is not showing any date fields.
What level of Date Year or Year and month?
Where are you putting the Year and or month you are going to use to select from the pivot.
 
Upvote 0
If you were to put 2021 in E23, it should just be.

=GETPIVOTDATA("[Measures].[Sum of Line Item Total]",'YTD GS'!$B$3,"[Monthly Orders Reports].[Org #]",[@[Org '#]],"[Monthly Orders Reports].[Date (Year)]",$E$23)
 
Upvote 0
Alex, rather than answer your question, please allow me ask a broader question first, because it may help to get to the final answer quicker. I am completely in uncharted territory for me, as I've only been using Pivot Tables for about 2 weeks now. I started using them out of a necessity for the completion of the sheet. Here is the problem I am running into which I can't logically figure out due to my lack of upderstanding with PT's.

My main sheet is a sales tracker which has a "Yesterday" section at the top, a "Month To Date" (MTD) section in the middle, and a "Year To Date" (YTD) section at the bottom. I am now working on the "YTD" section. I'm a little hazy with all of the PT date functions & filtering options. If I try to just filter the Pivot Table date portion so that it only ever shows "this year", then on the 1st day of the new year, it will be blank (right?) because there isn't any info yet, and I wont receive the final 2021 data. On the other hand if I leave the Pivot Table date unfiltered by not selecting "this year", then I need to have formulas which will somehow always grab the most recent year after the years begin to accumulate.

As for my table results, this is what I have in there
1617594979405.png
 
Upvote 0
If you were to put 2021 in E23, it should just be.

=GETPIVOTDATA("[Measures].[Sum of Line Item Total]",'YTD GS'!$B$3,"[Monthly Orders Reports].[Org #]",[@[Org '#]],"[Monthly Orders Reports].[Date (Year)]",$E$23)
But doesn't that make my sheet fragile? My sheet is going to grow exponentially. There will be more years to come, and the store list will grow significantly longer. E23 will be overwritten at some point, correct?
 
Upvote 0
You are going to tell the system what period you want somewhere.
If you don't apply a filter for a years pivot then you would get a manageable number of columns.
If you don't apply a filter to a years AND months pivot you will get number of years * no of months
At the days (yesterday) level your are going to get no of years * 365 which really becomes unwieldy.

If you go with a fully exploded Pivot it might look something like this.
(this is with a very small number of dates populated)
Also this is based on a standard Pivot Table not Power Pivot but the principle would be the same.

20210404 Power Pivot or PP GetPivot.xlsx
ABCDEFGHIJKLMN
29
30Sum of Line Item totalColumn Labels
3120202020 Total20212021 TotalGrand Total
32AprApr TotalFebFeb TotalMarMar TotalAprApr Total
33Row Labels4-Apr4-Feb4-Mar1-Apr4-Apr
342371,0201,0201,0201,0001,00010,00310,00310,04110,04420,08531,08832,108
358392,0202,0202,0202,0002,00020,00320,00320,04120,04440,08562,08864,108
3611933,0203,0203,0203,0003,00030,00330,00330,04130,04460,08593,08896,108
37124612,02012,02012,0204,0004,00040,00340,00340,04140,04480,085124,088136,108
38Grand Total18,08018,08018,08010,00010,000100,012100,012100,164100,176200,340310,352328,432
39
Monthly Orders Reports


If you then wanted to pull from that Yesterday, MTD & YTD it would look something like this.

20210404 Power Pivot or PP GetPivot.xlsx
ABCDEF
1Latest Date5/04/2021
2Yesterday4/04/2021
3
4
5Yestderday
6
7Org #Loc NameGS$ YesterdayMTDYTD
823710,04420,08531,088
983920,04440,08562,088
10119330,04460,08593,088
11124640,04480,085124,088
12
Table with getpivot
Cell Formulas
RangeFormula
B2B2=B1-1
C8:C11C8=GETPIVOTDATA("Line Item total",'Monthly Orders Reports'!$A$30,"Org #",[@[Org '#]],"Date",$B$2-DATE(YEAR($B$2),1,0)+1,"Months",MONTH($B$2),"Years",YEAR($B$2))
D8:D11D8=GETPIVOTDATA("Line Item total",'Monthly Orders Reports'!$A$30,"Org #",[@[Org '#]],"Months",MONTH($B$2),"Years",YEAR($B$2))
E8:E11E8=GETPIVOTDATA("Line Item total",'Monthly Orders Reports'!$A$30,"Org #",[@[Org '#]],"Years",YEAR($B$2))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top