Help with GetPivotData formula

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
708
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Made my first PivotTable.
I want to get data from the PivotTable into a cell on another sheet.
Using the GETPIVOTDATA function, I can retrieve data however...

This returns exactly what the formula says.
Excel Formula:
=(GETPIVOTDATA(" Products",ProductionPivot!$B$2,"Months",4,"Years",2023))

I want to retrieve data based on current month and year. (MONTH(TODAY()), YEAR(TODAY()) if possible.
How do I accomplish this?

Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
As @Skybluekid indicated, you are almost there.
=(GETPIVOTDATA(" Products",ProductionPivot!$B$2,"Months",MONTH(TODAY()),"Years",YEAR(TODAY()) ))
PS: I personally don't like having Today() in formulas. I would put it in a cell and then reference that cell.
 
Upvote 0
As @Skybluekid indicated, you are almost there.
=(GETPIVOTDATA(" Products",ProductionPivot!$B$2,"Months",MONTH(TODAY()),"Years",YEAR(TODAY()) ))
PS: I personally don't like having Today() in formulas. I would put it in a cell and then reference that cell.
When I use the reference "Months"(Today()) or year, I ge tthe #REF! error.
I don't know much about pivot tables, what am I missing?
 
Upvote 0
The #REF! error means that there is no cell in the pivot table matching the specific criteria. Are you sure there is a single cell matching Products data for May 2023 in the pivot table?
 
Upvote 0
The #REF! error means that there is no cell in the pivot table matching the specific criteria. Are you sure there is a single cell matching Products data for May 2023 in the pivot table?
Yes, "Months", "Years" are present in the pivot table.

This formula works however, it is specific to one month:
Excel Formula:
=(GETPIVOTDATA("Products",ProductionPivot!$B$2,"Months",4,"Years",2023))

I am trying to get the current month using this formula that returns the #REF! error:
Excel Formula:
=(GETPIVOTDATA("Products",ProductionPivot!$B$2,"Months",(Month(Today())),"Years",(Year(Today())) ))

I've even tried to use cell references for the current month and year and still getting the same error.
Excel Formula:
=(GETPIVOTDATA("Products",ProductionPivot!$B$2,"Months",ProductionPivot!$A$1,"Years",ProductionPivot!$A$2))
A1: =(MONTH(TODAY()))
A2: =(YEAR(TODAY()))

Can't figure it out...
 
Upvote 0
Does this work though:

=(GETPIVOTDATA("Products",ProductionPivot!$B$2,"Months",5,"Years",2023))
 
Upvote 0
Does this work though:

=(GETPIVOTDATA("Products",ProductionPivot!$B$2,"Months",5,"Years",2023))
Yes, this formula works, but how would I make it to where the values would always be for the current month?
If I am reading the formula correct, the formula will always display the value from May, 2023. (Not dynamic)
Excuse my ignorance, this is my first pivot table...
 
Upvote 0
@pujo, Rory was trying to make sure that you actually had data for May 2023 especially since it has only just clicked over into May and it would not be too surprising if you had no May data yet which would cause the REF error.

This is what the formula(s) look like at my end.
(although I have the data and pivot on the same sheet)

Note: Like I said previously I prefer not to have Today() in the actual formula.
1) It makes it easier to test the formula as you can try different dates.
2) It makes is easier to run a different period should you need to eg on the 1st of the month you still want last months figures

20230502 Pivot GetPivot Formula pujo v02.xlsm
ABCDEFGH
1Input
2YearsMonthsSum of ProductsMonth5
3202345800Year2023
4523800
52023 Total29600Result 123800=GETPIVOTDATA("Products",$B$2,"Months",$G$2,"Years",$G$3)
6Grand Total29600Result 223800=GETPIVOTDATA("Products",$B$2,"Months",MONTH(TODAY()),"Years",YEAR(TODAY()))
7With error handling23800=IFERROR(GETPIVOTDATA("Products",$B$2,"Months",$G$2,"Years",$G$3),"")
8
Sheet1
Cell Formulas
RangeFormula
G2G2=MONTH(TODAY())
G3G3=YEAR(TODAY())
G5G5=GETPIVOTDATA("Products",$B$2,"Months",$G$2,"Years",$G$3)
H5:H7H5=FORMULATEXT(G5)
G6G6=GETPIVOTDATA("Products",$B$2,"Months",MONTH(TODAY()),"Years",YEAR(TODAY()))
G7G7=IFERROR(GETPIVOTDATA("Products",$B$2,"Months",$G$2,"Years",$G$3),"")
 
Last edited:
Upvote 1
Solution

Forum statistics

Threads
1,215,223
Messages
6,123,727
Members
449,116
Latest member
Aaagu

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