Using Date with GetPivotData - excel

I have a pivot table that I am trying to reference using a date as part of the lookup. The pivot table data can be grouped by day, week or month (there is a little VBA that controls this) However, I cannot seem to create a GETPIVOTDATA function that will work with all three groupings.
- When grouped by day, GETPIVOTDATA seems to want the day of the year (1-365), it won't accept a date.
=GETTPIVOTDATA(value, pt, "Date", 184)
When grouped by week, it will accept a date and return the week that the date falls in
=GETTPIVOTDATA(value, pt, "Date", Date(2012, 08, 22))
When grouped by month, it seems to want the month of the year (1-12)
=GETTPIVOTDATA(value, pt, "Date", 11)
Is there anyway to use a date with all three groupings? Bear in mind that the groupings will change but the formula won't so the same formula has to work with any grouping.
The alternatives are using an IF statement and date manipulation or using VBA whenever I change the groupings. However, I feel that the should be a way to just use the date, regardless of the grouping.

Related

Month & Week grouping in excel pivot tables with some empty data

I am working to group data in excel and I am trying to sort the input dates by month and week. I've found a number of ways to group by weeks (including grouping the date by 7 days and adding a helper column in the pivot table that numbers the weeks), but I'm having a problem viewing months and weeks without data.
For example, in my data set during the month of October, 2 of the weeks have no input. When I try to make the pivot table "show rows with no data" it shows every week in the year, not only the weeks during the month of October.
I would like be able to show every week during the month of October, including those without data, without showing every week in the year. Has anyone encountered a similar issue? I'm on Excel 2016 but my colleague has the same issue on Excel 2013.
Thanks!
Here is a quick screenshot of the pivot table from the data. I am trying to make all of the weeks in the month of October show up regardless of whether or not there is data, but I don't want to see all of the weeks in the date range. I have sample data input from September 16th, 2018 to January 1st, 2019
Update for anyone looking to do this themselves:
I couldn't figure out a way to do this with Pivot Charts. They lack the ability to group by multiple days as well as by months and years. Instead, I used VBA to select the desired data from the pivot table by checking for the number of the month in each row. (mm/dd/yyyy - mm/dd/yyyy is the format pivot tables use to group days).
I added a dummy row which copied the date ("Date 2") and used that, grouped in 7 days, as the rows for the pivot table. Because I wanted to show items with 0 data I selected that option, which shows every group of 7 days from the first day entered until the last day entered. I used the original Date with Month and Year auto groups to insert Slicers to sort the data.
In VBA you can check which Slicers are selected and use that to determine the range of months you want to display on the inserted chart. This way you can look at one or two months at a time but still show weeks with no data.
While this solution is not particularly elegant, it did allow for a dynamic use of the data that can be adjusted to view specific months or years as was desired. Some useful resources for this method are included below. Again, it is an ugly way to get the desired result but if it works it works!
https://peltiertech.com/referencing-pivot-table-ranges-in-vba/
https://peltiertech.com/create-update-chart-using-partial-pivot-table/

Retrieving specific data from column in pivot table

The data in my pivot table is sorted according to the date (oldest to newest). The column with dates is only comprised of business days. I have formulas to retrieve data from the latest and earliest dates using MAX and MIN functions. Let's say the latest date is 2017-06-30 and the earliest date is 2016-10-01. Then the following functions retrieve the desired data from those dates. (Column A is the date column).
=GETPIVOTDATA("A";$A$4;"B";"C";"TO_DATE";MAX(A:A);"D";"E") =GETPIVOTDATA("A";$A$4;"B";"C";"TO_DATE";MIN(A:A);"D";"E")
Note that I have hidden some of the column names. What I would like to do now is to get data from 5 business days/30 business days/90 business days before the date specified by
=GETPIVOTDATA("A";$A$4;"B";"C";"TO_DATE";MAX(A:A);"D";"E").
Is there a way to accomplish this without using the WORKDAY function where I have to specifiy the holidays? This was my initial thought, but I don't want to specify the holidays, so the following function won't work
=GETPIVOTDATA("A";$A$4;"B";"C";"TO_DATE";WORKDAY(MAX(A:A);-5);"D";"E")
I tried to use the OFFSET function, however it seems that I can't use the cell value as a cell reference.

Format date and Value

I have a synchronized List from SharePoint in Excel with Date, Names and sold items to sume.
The Date appears as Datetime(2017-01-01 13:00:00).
In order to do a Pivot Table I wanted to Format it so only appears the month and the year. (January 17).
The Problem is, although the Date is in Month-Year Format, when I do the Pivot table it seems to get the original values of the date, so it doesn´t recognize "January 17" as a Month and it repeats the field several times because it still recognize it as a DateTime value and I can´t get the sold items of one month.
Please have a column to convert the format 2017-01-01 13:00:00 to January-17
If the datetime is in cell A1 use the formula below,
=TEXT(A1,"mmmm-yy")

Excel Pivot Table Grouped Dates

I inserted a pivot table with a named table as the data source, and am using the date value as a Column Label. The dates are either 1/0/1990(blanks), late December 2015, or early January 2016.
I would like to only display dates from 2016, so I used the "Date Filter" to only show values from this year (I tried doing this both by entering the dates manually, and just selecting "This Year").
http://i.stack.imgur.com/VeTO7.png
However when I do this I can now select to see dates "<1/1/2015",any of the months, or ">12/31/2015". Obviously if I want to see items from 2016, this is not much use, as they are all grouped under one "grouping checkbox" (">12/31/2015").
http://i.stack.imgur.com/rmm9y.png
So right now, with all of my 2016 dates falling under January, the only column label visible is ">12/31/2015", instead of showing "Jan".
http://i.stack.imgur.com/L5eza.png
How can I get the pivot table to display the month names for my data, instead of ">12/31/2015"?
http://i.stack.imgur.com/M8IF4.png
The solution that I found (which may not work for everyone), is to check how you grouped your dates, as Excel's automatic grouping incorrectly guessed my date range. Another solution is to make sure you are applying the date filter before you are grouping, instead of after.

Pivot table cannot find difference between January current year to December of previous year. Excel 2010

I am weeks into making my first ever pivot tables, cant believe the power of them but have hit a snag I cannot overcome.
I have a worksheet which has a column with raw data (manually imputed)
Then I have another 2 columns that calculate the difference from the previous month and the % difference. This works fine.
As you can see January 2015 is blank as the difference field is looking for the previous month and January is the first month.
how can I get it to understand to look at December 2014
When there are two different levels of grouping, i.e. Year and Month, it is not possible to get Excel to compare the last item of one group with the first item of the previous group.
Excel treats the additional level of grouping as a different field, which is visible when looking at the PivotTable fields. The Years of the Date show as a separate field:
When choosing to calculate the difference, Excel can only compare to values within the same field. Note that you can compare to a specific month value, but not a specific month of a specific year:
Similarly, Excel can't compare to values from the previous grouping, even though human-logic knows it's the previous value in the overall sequence.
To see the difference between each month across years, it's necessary to have all Year-Months in a single field. This isn't possible using PivotTable grouping on normal dates.
The workaround requires a new field to be added to the data which contains a single value per Year-Month. The PivotTable will then naturally group the data by these Year-Month values.
There are two ways this can be achieved:
Calculate the first day of each Year-Month
Insert another column with this formula (referring to a date in the A2 cell):
=Date(Year(A2),Month(A2),1)
This performs the grouping before the data goes into the PivotTable by treating every date as the first of the month. In the PivotTable, the full date will appear by default. You can apply Custom Number Formatting to the field to display only the Month and Year, for example: "mmm yyyy"
This is a better solution when grouping by months as it allows more formatting options.
Calculate a text value for each Year-Month
Insert a column with this formula:
=TEXT(A2,"yyyy mm")
For example, the following data:
Can generate this PivotTable (with sums and then differences):
The text solution has the drawback that you must specify the Year and then Month numerically (and padded to 4 and 2 digits respectively) if you want the PivotTable to automatically order the values in chronological order.
The benefit of the text solution is greater flexibility. For example, you could group bi-monthly with more advanced formulas or group two fields of actual data together by concatenation.
Have you tried combining the month and year in one cell? So on the source data, in the month column have:
Aug-14
Sep-14
Oct-14
Nov-14
Dec-14
Jan-15
Instead of having one column for month name and one for year.
Make sure that once you input the months in your raw data tab, they go to the right side of the cell meaning that Excel sees them as dates not text.

Resources