Problem with INDEX function to return top 3 objects and sizes from a list

R

Roger

SHEET1: Hundreds of entries in no particular order. Note: there are
other columns between these fields. This is only an example.
NAME SIZE
A 1
B 5
C 3
D 12

SHEET2: On a separate sheet, I want to display the top 3 largest Names
with their corrosponding sizes
NAME SIZE
D 12
B 5
C 3

Here's what I'm using...
=INDEX(Tables!A4:O500,MATCH(LARGE(Tables!M4:M500,1),Tables!M4:M500,0),1)
LARGE: to find the largest, 2nd largest, and 3rd largest values
MATCH: to pass a row number to INDEX
INDEX: to return the value of the field I want

The problem is when 2 or more of my top 3 objects have the same size.
If I have this…
NAME SIZE
A 1
B 12
C 3
D 12

then I get this…
NAME SIZE
B 12
B 12
C 3

I want this…
NAME SIZE
B 12
D 12
C 3

I understand why this is happening. MATCH is returning the first row
number it encounters that matches the value returned by LARGE. The
problem is that I do not know how to fix it.

By the way, this might seem advanced but it really only means I'm good
at reading the help docs.
I'm an Excel newbie so please be as specific as possible!
Thanks in advance!

Roger
 
H

Harlan Grove

Roger said:
The problem is when 2 or more of my top 3 objects have the same size.
If I have this…
NAME SIZE
A 1
B 12
C 3
D 12

then I get this…
NAME SIZE
B 12
B 12
C 3

I want this…
NAME SIZE
B 12
D 12
C 3
....

The trick is to exclude values already found. If the original data were in
A2:B100, with letter in col A and numbers in col B, the topmost result could
be found with

Y2 - Letter:
=INDEX(A$2:B$100,MATCH(MAX(B$2:B$100),B$2,B$100,0),1)

Z2 - Value:
=INDEX(A$2:B$100,MATCH(MAX(B$2:B$100),B$2,B$100,0),2)

Then for the next set of results try

Z3 - Value: [array formula]
=IF(COUNTIF($B$2:$B$100,Z2)>COUNTIF(Z$2:Z2,Z2),Z2,
INDEX($A$2:$B$100,MATCH(MAX(IF($B$2:$B$100<Z2,$B$2:$B$100)),
$B$2:$B$100,0),2))

Y3 - Letter: [array formula]
=INDEX($A$2:$B$100,IF(Z3<Z2,MATCH(Z3,$B$2:$B$100,0),
SMALL(IF($B$2:$B$100=Z3,ROW($B$2:$B$100)-1),COUNTIF(Z$2:Z3,Z3))),1)

Select Y3:Z3 and fill down as far as needed.
 
H

Harlan Grove

...
...
Z3 - Value: [array formula]
=IF(COUNTIF($B$2:$B$100,Z2)>COUNTIF(Z$2:Z2,Z2),Z2,
INDEX($A$2:$B$100,MATCH(MAX(IF($B$2:$B$100<Z2,$B$2:$B$100)),
$B$2:$B$100,0),2))
...

Unnecessary. Leave this something like

Z3 - Value:
=INDEX($A$2:$B$200,MATCH(LARGE($B$2:$B$100,ROW()-1),$B$2:$B$100,0),2)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top