GETPIVOTDATA formula to return the total of a item within a given month - excel

In my pivot table. I have my data setout like this..
M1 M2 M3
Country Item
Australia Item 1 5 3 3
Item 2 3 6 7
Item 3 4 6 6
Australia Total 12 15 16
Belgium
Item 1 4 5 7
Item 2 5 8 3
Item 3 3 7 3
Belguim Total 12 20 13
What im trying to do is get the total of Item 1 in M1 (which is 9) using the GETPIVOTDATA function.
Ive already been able to get the Country Totals for M1 using "Australia Total" "M1".

I thought this was possible, but looking at Excel 2010 help it seems to say that you can only refer to a total that's visible somewhere in the table. So, I think you need another pivot table that has doesn't include countries. Or you could change the one above so that Countries are to the right of Items. Then point your GetPivotData formula at that.
The specific line from the Excel page linked above is the last one: "returns #REF! because there is no total value of beverage sales for Davolio."
EDIT: If you want to use variables in your GetPivotData formulas this Contextures page has some great tips, especially the one at the end about referring to the Data field.

Only numbers shown on the sheet can be returned by returned by the GETPIVOTDATA function. In this case the solution could be to drag the Item field to the column. If now a cell with the number 9 is shown, you are able to retrieve it.

Related

Create filter for a drop down list that groups several rows together

I have the following table:
A
B
C
1
Team
2
Team1
Working hours
10
3
Name
Ronald
4
Team2
Working hours
20
5
Name
Magda
6
Team1
Working hours
30
7
Name
John
Column (A2:A7) represents a dropdown list of {Team1, Team2}
Cell A1 selects the filter for that
I want now select in cell (A1) all data from Team1, to have a table looking like:
A
B
C
1
Team: Team1
2
Team1
Working hours
10
3
Name
Ronald
6
Team1
Working hours
30
7
Name
John
Does anyone know, if that is possible?
A solution would be, to fill every cell of column A with the Team value. However, this is not what I like
Another solution (I guess) is to connect these cells, but this makes it rather complicated if I want to add another attribute per team member (besides Working hours and Name)
I suggest you change your data orientation to be like this (check below picture):
I think it should do the job
How about the following?:
=IF(FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1))="","",FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1)))
This solution requires Office365.
The length of both ranges in the filter criteria need to be the same size (row numbers) as the range you want to filter. The range Just shifts (offsets) 1 row to have the second row showing.
Added an IF-argument to show blank cells as blank (they would appear as 0 otherwise).

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

Getting the next higher value with VLOOKUP or INDEX/MATCH

I have the following Excel spreadsheet:
A B C D
1 0 Product 1 7.500 Product 4
2 1.000 Product 2
3 5.000 Product 3
4 10.000 Product 4
5
In Cell C1 I type a random number (in this case 7.500). Now I want that in Cell D1 the corresponding Product is shown to the value in Cell C1. Since 7.500 does not exist in Column A the next higher value should be used. In this case 10.000 which belongs to Product 4.
I tried to go with the following formula in Cell D2 but instead of getting Product 4 I get #NV as a result.
=INDEX(A1:B4;MATCH(C1;A1:A4;-1);2)
The only solution I found so far was changing the values in Column A from ascending to descending. However, I would prefer to have a solution which does not require a change of the order in the list.
Do you have any idea how to solve this issue without changing the order in the list?
For unsorted data you can use below formula::
=INDEX(B1:B4,MATCH(SMALL($A$1:$A$4,COUNTIF($A$1:$A$4,"<"&C1)+1),A1:A4,0))
See image for reference

Excel lookup 2 Values

I'm sorry if this is an obvious question, but I've been searching and can't seem to figure this out..
Cost TableCost Table
Employee Date Hours
2 03/16/16 8
2 03/17/16 8
2 03/20/16 8
3 03/21/16 8
3 03/22/16 8
5 03/23/16 10
6 03/24/16 4
6 03/28/16 5
Time Clock Table
Employee Date Hours
2 03/16/16 1
2 03/17/16 3
2 03/20/16 2
3 03/21/16 5
3 03/22/16 4
5 03/23/16 7
6 03/24/16 7
6 03/28/16 7
I just want to lookup on this table to see how many hours each employee worked on a certain date. They are cheating the system and we need to find out who's short.
You can use a formula like this
=INDEX(TableCostTable[Hours],MATCH([#Employee]&[#Date],INDEX(TableCostTable[Employee]&TableCostTable[Date],0),0))
It concatenates the name and the date and uses Index/Match to look up the same combination and returns the hours. The formula uses structured references with the column names and header names. It will also work if you use sheet names and cell references, but don't use it with whole columns, because that will be very slow.
You need a SUMIFS rather than a VLOOKUP, in this case
=sumifs(Paytable!C:C, Paytable!A:A,2,Paytable!B:B,date(2016,3,17))
You can solve this through a SUMIFS formula, such as:
=SUMIFS(C:C, A:A, 2, B:B, "03/07/16")
What this is doing is summing all values in column C where column A is equal to 2 (for the employee) where column B is equal to 03/07/16.

Excel: Trailing 3 month decline using data from a pivot table

(http://stackoverflow.com/questions/5283466/calculate-moving-average-in-excel seems to be somewhat related. I'm curious to know the non-vba way to do this.)
My my pivot table has source data that creates a count of how many sales a person had in the past 36 days. Each day os 1 column in the pivot table, and the persons name is on the row.
Some of these people did not have sales on day1, day2, etc, and may only have 3 days where they sold something on days 14,15 and 16. No matter what their sequence, I want to to find the most recent sale data (closest to the right edge of pivot table) and calculate three sales increases e.g. C20/C19 will be >1 if they had more sales on the whatever day C20 is. The increase ca nbe fond by subtracting 1 and changing to percent. The problem is, if a person only had sales on d10, d11, d12 then how can I put a general formula in Excel to say "look for the most recent consecutive sales, then calculate this ratio"? For a person who had sales in the past three days, that's easy. It will be chaotic to hardcode where to look for each sales value.
d1 d2 d3 d4...d7 d8 d9...d34 d35 d36 mostrecentincrease nextrecent
ant 1 5 7 7/5=1.4 5/1=5
bat ...10 11 12... 12/11=1.blah 11/10=1.1
cat 2 6 9 13
dog 19 20 20/19=1.blah 19/blank=0
elf 4 4/dnexist=0
i don't have excel here, but i hope this will guide you to the correct result (use , instead of ; if that is your list separator):
define sales as a range of values from d1 to d36 for a given row (or use actual ranges)
compute positions of the last values for each row using these array formulas (use ctrl+shift+enter instead of just enter after you write these formulas):
position_1 =max(if(sales<>0;column(sales)))
position_2 =max(if((sales<>0)*(column(sales)<>position_1);column(sales)))
position_3 =max(if((sales<>0)*(column(sales)<>position_1)*(column(sales)<>position_2);column(sales)))
retrieve the values:
value_1 =index(sales;position_1)
do some error handling (=iferror(...;0)) and the like...

Resources