Find the nth Value in an Index(Match list

jamesuk

Board Regular
Joined
Sep 8, 2015
Messages
85
Hi All

hope you're all well?

Is it possible to have an index(match look at and retrieve the value of the nth occurrence in an array?

For example. if in Column A I have:

Cat
Dog
Cat
Monkey
Elephant

then in column B I have:

1
3
5
6
8

I want my index match to return the value of the 2nd occurence of Cat (so, 5), how could I do this please?

Code:
  =INDEX(A1:B5,MATCH("Cat",A1:A5,0),2)
would return 1


Many thanks in advance for your help! :)
 
If using Excel 2010 or later an option without the need for Ctrl+Shift+Enter

Match Nth

*
A
B
C
D
E
Cat
*
Dog
*
Cat
*
Monkey
*
*
*
Elephant
*
*
*
*
*
*
*
*

<tbody>
[TD="bgcolor: #CACACA, align: center"]1
[/TD]

[TD="align: right"]1
[/TD]

[TD="align: right"]Value
[/TD]
[TD="align: center"]Cat
[/TD]

[TD="bgcolor: #CACACA, align: center"]2
[/TD]

[TD="align: right"]3
[/TD]

[TD="align: right"]Occurence
[/TD]
[TD="align: center"]2
[/TD]

[TD="bgcolor: #CACACA, align: center"]3
[/TD]

[TD="align: right"]5
[/TD]

[TD="align: right"]Result
[/TD]
[TD="align: center"]5
[/TD]

[TD="bgcolor: #CACACA, align: center"]4
[/TD]

[TD="align: right"]6
[/TD]

[TD="bgcolor: #CACACA, align: center"]5
[/TD]

[TD="align: right"]8
[/TD]

[TD="bgcolor: #CACACA, align: center"]6
[/TD]

</tbody>

Spreadsheet Formulas

Cell
Formula
E3
=INDEX($B$1:$B$5,AGGREGATE(15,6,(ROW($B$1:$B$5)-ROW($B$1)+1)/($A$1:$A$5=E1),E2))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4


Hi Peter,

Would you be able to explain how exactly this is working? I understand the aggregate is using the small function (only ignoring errors), but how else is everything working? The Row()-Row()+1/A1:A5=E1 portion is the part I'm struggling with.

Also, is it possible to expand the number of exclusions? For example, if A6 = Cat and B6 = 20, would I be able to run the same function but return the 2nd occurrence excluding anything in column B that = 5? This would make the result = 20
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Peter,

Would you be able to explain how exactly this is working? I understand the aggregate is using the small function (only ignoring errors), but how else is everything working? The Row()-Row()+1/A1:A5=E1 portion is the part I'm struggling with.

Also, is it possible to expand the number of exclusions? For example, if A6 = Cat and B6 = 20, would I be able to run the same function but return the 2nd occurrence excluding anything in column B that = 5? This would make the result = 20

(ROW($B$1:$B$5)-ROW($B$1)+1) is used to construct an array of the relative row numbers of the range to be indexed. In the example referred to {1,2,3,4,5}
The reason that construct is used and not simply ROW($B$1:$B$5) [which would also produce the array {1,2,3,4,5}] is to protect the integrity of the formula if rows are subsequently inserted at the top of the sheet.
If one row was inserted, the range to be indexed would now be B2:B6. The first construct will still produce the array {1,2,3,4,5}, which is what we want to refer to one of the cells in the range, whereas the second construct would now return {2,3,4,5,6} which would produce incorrect results or an error.

To ensure multiple conditions are met the extension of such a formula is
=INDEX(range,15,6,row_array/((Condition 1) * (Condition 2) * (Condition 3) ....),N)
If any of the conditions are false, the denominator of the division will be zero, producing an error and caus that row to be ignored.

So, for your example above you could use ..

Excel Workbook
ABCD
1Cat120
2Dog3
3Cat5
4Monkey6
5Elephant8
6Cat20
Match Nth
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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