Index and Match

m3ko

New Member
Joined
Apr 3, 2024
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Hi everyone,

Could I get some help with my formulae.
Below is my pivot table I created from a data source.
I defined this as PivotTableRange under sheet called Data - Pivot using
=OFFSET('Data - Pivot'!$A$1, 0, 0, COUNTA('Data - Pivot'!$A:$A), COUNTA('Data - Pivot'!$1:$1))

Sales history type.xlsx
ABZAAABACADAEAFAGAH
1Sum of TrnQty
2StockCodeMovementType20182019202020212022202320242025Grand Total
310101aS11
441016.5I3.548.476050.5910.01172.57
541016.5S1.461.46
Data - Pivot


On my main usage sheet called "Summary", I want to look up items and have it return the Grand Total.
But, it must meet 2 criteria since each item can either be in Movement type "S" or "I" as shown in my PivotTableRange (on sheet named Data - Pivot).
The problem I am having is that as I refresh my pivot table with new data, I expect the columns to change so the Grand Total from the Pivot Table will be dynamic.
The start year is blank for some of the items, so I think that is messing with my formula as it is returning values before the next blank column, which in this case is one of the lookup criteria of "S".

=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!1:1))

Sales history type.xlsx
BCDEF
2Manual Lookup:
3Stock CodeProduct ClassQty On HandTestYtd Sold
441016.530SP0S50.59
Summary
Cell Formulas
RangeFormula
C4C4=IFERROR(VLOOKUP($B$4,StkInfo,2,FALSE),"")
D4D4=IFERROR(VLOOKUP($B$4,StkInfo,4,FALSE),"")
E4E4=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!1:1))
F4F4=IFERROR(VLOOKUP($B$4,StkInfo,5,FALSE),"")
Named Ranges
NameRefers ToCells
PivotTableRange=OFFSET('Data - Pivot'!$A$1, 0, 0, COUNTA('Data - Pivot'!$A:$A), COUNTA('Data - Pivot'!$1:$1))E4



Could I get some assistance or directed to a solved thread please!
Thanks everyone!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I defined this as PivotTableRange under sheet called Data - Pivot using
=OFFSET('Data - Pivot'!$A$1, 0, 0, COUNTA('Data - Pivot'!$A:$A), COUNTA('Data - Pivot'!$1:$1))
Wouldn't you have used row 2?

.. and the same in your formula?
=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!2:2))
instead of
=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!1:1))

Also, do you need to go to the trouble of defining the named range? You could use something like this instead. Just make the ranges plenty big enough to accommodate any future Pivot Table expansion.
=INDEX('Data - Pivot'!A:ZZ, MATCH(1, ('Data - Pivot'!A1:A1000=B4)*('Data - Pivot'!B1:B1000="S"), 0), COUNTA('Data - Pivot'!2:2))
 
Upvote 0
Solution
Wouldn't you have used row 2?

.. and the same in your formula?
=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!2:2))
instead of
=INDEX(PivotTableRange, MATCH(1, (INDEX(PivotTableRange, 0, 1)=B4)*(INDEX(PivotTableRange, 0, 2)="S"), 0), COUNTA('Data - Pivot'!1:1))

Also, do you need to go to the trouble of defining the named range? You could use something like this instead. Just make the ranges plenty big enough to accommodate any future Pivot Table expansion.
=INDEX('Data - Pivot'!A:ZZ, MATCH(1, ('Data - Pivot'!A1:A1000=B4)*('Data - Pivot'!B1:B1000="S"), 0), COUNTA('Data - Pivot'!2:2))

OMG thanks so much Peter, I'm such an idiot.
This started out as something different and I later went back to add in to add a second condition (MovementType).
Did not update it to use row 2 instead on the named range and everything.
Hopefully I can get better and be able to offer solutions too one day.
Is there a book or something out there that you used before XD?

Orz.

Thanks for the solution, cheers!
 
Upvote 0

Forum statistics

Threads
1,223,929
Messages
6,175,448
Members
452,642
Latest member
acarrigan

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