Top "N" List with Selection Criteria

NeedInformation

New Member
Joined
Feb 23, 2014
Messages
14
Office Version
  1. 2021
Platform
  1. Windows
Would appreciate help with the following.

I have a large, unsorted table in one worksheet tab and I need to populate a sorted TOP N list on another worksheet tab where TOP is the largest amount of sales (largest being #1 ) but it has to be only with those of a certain color. I need to return the KEY into the TOP N table. KEY is guaranteed to be unique in the source table. From the KEY I can retrieve any additional needed data to populate the target tab. There can be duplicate sales amounts. In fact, anything can be duplicated save for the KEY value.

KEYSalesColorName
asdf100RedSam
qwer200blueNick
zxcv100RedMary
54632000GreenSally
fghj150RedMark
yuio300YellowTom
cvbn275BlueRalph
ghjk500RedSara
ghjz750BlueRita

<tbody>
</tbody>

So, a top 3 list based on Red would return TOP=3, COLOR=RED

Key
ghjk
fghj
asdf

<tbody>
</tbody>


In the case of duplicate, a top-down selection would be fine as illustrated by the key asdf as opposed to zxcv above.

If SALES has to be part of the solution to help find the key that's okay.

Formulas are the preferred solution vs macro(s).

TIA!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
See if this will help?
A​
B​
C​
D​
1​
KEYSalesColorName
2​
asdf
100​
RedSam
3​
qwer
200​
blueNick
4​
zxcv
100​
RedMary
5​
5463​
2000​
GreenSally
6​
fghj
150​
RedMark
7​
yuio
300​
YellowTom
8​
cvbn
275​
BlueRalph
9​
ghjk
500​
RedSara
10​
ghjz
750​
BlueRita
11​
12​
Top
3​
colorRed
13​
ghjk
14​
fghj
15​
asdf
B12=top N
D12 = color
A13=IF(ROW(A1)>$B$12,"",INDEX($A$2:$A$10,MATCH(LARGE(IF($C$2:$C$10=$D$12,$B$2:$B$10),ROW(A1)),$B$2:$B$10,0)))
ARRAY entered using CTRL SHIFT ENTER, not just enter
Then copy down as needed
 
Upvote 0
@FDibbins - I think there may be a couple potential problems with your formula. 1) In the above example for RED if the Sales in Row 3 for Blue had been 500 your formula will pick up the Key for Blue and not Red. 2) If you were to look for the top 4 your formula will only pick up one of the Key's for Sales at 100.

Try:
This is also an array formula that must be entered with CTRL-SHIFT-ENTER.

Excel Workbook
ABCD
1Top4colorRed
2ghjk
3fghj
4zxcv
5asdf
Sheet2
Excel Workbook
ABCD
1KEYSalesColorName
2asdf100RedSam
3qwer200blueNick
4zxcv100RedMary
554632000GreenSally
6fghj150RedMark
7yuio300YellowTom
8cvbn275BlueRalph
9ghjk500RedSara
10ghjz750BlueRita
Sheet1
 
Upvote 0
At first glance this seemed perfect but then, as a test, I changed sheet1!b9 to 1. Sheet2 didn't change. I have automatic calculation turned on. Is this a nuance of Excel or am I missing something? I need to ensure Sheet2 is automatically updated when changes in Sheet1 occur and sheet2 remains sorted based on Sales in descending order.

@FDibbins - I think there may be a couple potential problems with your formula. 1) In the above example for RED if the Sales in Row 3 for Blue had been 500 your formula will pick up the Key for Blue and not Red. 2) If you were to look for the top 4 your formula will only pick up one of the Key's for Sales at 100.

Try:
This is also an array formula that must be entered with CTRL-SHIFT-ENTER.

Sheet2

ABCD
1Top4colorRed
2ghjk
3fghj
4zxcv
5asdf

<colgroup><col style="width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
A2{=IF(ROWS($A$2:A2)>$B$1,"",INDEX(Sheet1!$A$2:$A$10,LARGE(IF(Sheet1!$C$2:$C$10=$D$1,ROW(Sheet1!$C$2:$C$10)-ROW(Sheet1!$C$2)+1),ROWS($A$2:A2))))}

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>


Sheet1

ABCD
1KEYSalesColorName
2asdf100RedSam
3qwer200blueNick
4zxcv100RedMary
554632000GreenSally
6fghj150RedMark
7yuio300YellowTom
8cvbn275BlueRalph
9ghjk500RedSara
10ghjz750BlueRita

<colgroup><col style="width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:66px;"><col style="width:68px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
You're right I also gave you a bad formula.

Try this (I added a Sales column)
These are array formulas and must be entered with CTRL-SHIFT-ENTER.

Excel Workbook
ABCD
1Top3colorRed
2SalesKey
3150fghj
4100asdf
5100zxcv
6
Sheet2
Excel Workbook
ABCD
1KEYSalesColorName
2asdf100RedSam
3qwer200blueNick
4zxcv100RedMary
554632000GreenSally
6fghj150RedMark
7yuio300YellowTom
8cvbn275BlueRalph
9ghjk1RedSara
10ghjz750BlueRita
Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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