Retrieving specific data from column in pivot table - excel

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.

Related

Excel - Take Average of Monthly Data

I have a historical data set for commodity pricing. Throughout the data set, the data starts inputting prices on specific days, rather than the average of the entire month. In order to keep the flow of having only the average pricing for the months.
In the best case scenario, I would use an Averageif function, however, the data for each month doesn't display a consistent amount of days.
How can I automate this the process: If the month is the same as the previous row and different than the next row, calculate the average of the ^ rows until you hit the next month.
Here's a simple display of what I mean:
]1
You can use a pivot table to get the output you want. It will also be neatly organized instead of having your averages mixed in with a mostly blank column. Photo below shows the set-up/output of a pivot table generated with random data.
For a solution without pivot tables, you can use the following formula :
=AVERAGEIFS($B$1:$B$30;$A$1:$A$30;">="&(A1-DAY(A1)+1);$A$1:$A$30;"<="&EOMONTH(A1;0))
The above example is from cell C1, and can be copied down the entire list. The dates are in $A$1:$A$30 and the values in $B$1:$B$30. The first conditions test on the first day of the month (calculated as A1-DAY(A1)+1),and the second condition as last day of the month (calculated as EOMONTH(A1;0)
This will obviously put the average value of the month on each row, but will also work if your data is not sorted on date. If this is the case, and you only want to display one number per month in the column (as in your own example), you can add an additional IF statement wrapped around the formula:
=IF(EOMONTH(A2;0)=EOMONTH(A1;0);"";AVERAGEIFS($B$1:$B$30;$A$1:$A$30;">="&(A1-DAY(A1)+1);$A$1:$A$30;"<="&EOMONTH(A1;0)))
So it will display empty in all cells, except where the month changes.

How to convert a list of text with dates and purchases into a table that shows purchases for every date with Excel VBA?

I am trying to convert a list of text into a table that shows all the purchases for a particular date.
The data looks like this, and it is all in one column:
The data follows the format of:
Job Number
Price
Date
Email of customer
Product code
I am trying to convert the data into a table which will end up looking like this:
I would like to see all the purchases listed below the dates.
Is this possible with VBA in Excel?
I found an extremely inelegant solution to the problem, but without VBA.
Here is the original column of data:
[orginal data]
In order to separate the dates into a separate column, I used this formula in column B:
=IF(AND(ISNUMBER(A2),A2>40000),MONTH(A2)&"/"&DAY(A2)&"/"&YEAR(A2),"")
If you convert the date into a number, it will be greater than 40000, and since the purchases do not exceed 400000, we can see that all numbers greater than 40000 will be a date. Since the date includes the specific time of day, and we are only looking for the actual day, I used the MONTH, DAY, and YEAR questions to select only the date.
Next, I wanted to line up the purchases with the respective dates for the orders, so I used this formula to check to see if the value in column A is a number, and if it is, copy it over to column C.
=IF(AND(ISNUMBER(A1),A1<40000),A1,"")
The formula was placed in C2 so that it lines up the purchases with the dates.
The spreadsheet now looks like
this.
Next, you select columns B and C and create a pivot table- problem solved!

Is it possible to output the values of a column in excel based on a dynamic date value?

In the following table I have weeks as columns, employees as rows and the values are the amount of holiday days per employee per week taken.
I want to create a separate table as a dashboard where the output will change depending on the date I input into the date selector. In the example below, I have chosen the 2/11/2015 as my week and I would like to only see the corresponding values for that week in the output table. How do I go about doing this?
Try this in B5:
=Index($B$34:$F$48,MATCH($A5,$A$34:$A$48,0),MATCH($C$1,$B$33:$F$33,0))
Then copy down.
Change the F column References in the formula to get the extent of you columns of data.
As a Note: If you are in a country that use ; as the delimiter between criteria instead of , here is the formula with those delimiters:
=Index($B$34:$F$48;MATCH($A5;$A$34:$A$48;0);MATCH($C$1;$B$33:$F$33;0))

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.

Excel to specify the month to report the data

Using excel, is it possible to specify the month to report in a cell?
For example, excel would need to report the latest reported sales, if its available. If the month of February sales is not available, then it will report January sales. Likewise, if March sales is available, it would report the sales in March.
How do you write this formulae in a cell in excel? If its not possible to write such a formuale, can we write a vba to do this?
If you mean you have a list of sales entries and want the sales for the last month in the data, you could write one formula to get the latest month. If months are in A you could write: =month(max(A1:A99999))
Note if you have multiple years data, you need to pull the year too or get bounding dates. You can then sum sales using an array formula like assuming the result of the first action is in D1 and sales are in B: {=sum(if(month(A1:A999999)=D1,B1:B999999,0))}
If you have incremental updates during the month, this will return month to date data. If you need data for the last full month, you can use another array formula to get the maximum month where the date is the last day of the month.
If the cells for future data in B1:B12 are blank then you just need to extract the last number in B1:B12 don't you? If so then try
=LOOKUP(9.99E+307,B1:B12)
You can use the OFFSET function to select specific data based on the month.
Insert a formula to calculate the current month (or just type in the month number)
=MONTH(TODAY())
The formula to select the current months of sales data
=SUM(OFFSET(B1,MONTH(TODAY()),0,1,1))
Have a look at the help in Excel on the OFFSET function. It can be used to select a range of data. For example, to return data from the start of the year to the current month the formula would be:
=SUM(OFFSET(B1,1,0,MONTH(TODAY()),1))
If the current month does not contain data yet, you can test to see if a value is returned and revert to the prior month if there is no data.
=IF(SUM(OFFSET(B1,B16,0,1,1))=0,SUM(OFFSET(B1,B16-1,0,1,1),SUM(OFFSET(B1,B16,0,1,1))))
I found this answer:
=IF(B12<>0,B12,IF(B11<>0,B11,IF(B10<>0,B10,IF(B9<>0,B9,IF(B8<>0,B8,IF(B7<>0,B7,IF(B6<>0,B6,IF(B5<>0,B5,IF(B4<>0,B4,IF(B3<>0,B3,IF(B2<>0,B2,IF(B1<>0,B1,0))))))))))))
This formulae solves the problem of picking up the latest available data.

Resources