Returning top 3 list with duplicates using INDEX, MATCH, IF, SMALL & TEXTJOIN

Dlloyd15

New Member
Joined
Feb 20, 2020
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Firstly I'd just like to say I'm fairly new at using extensive functions in Excel, so if I've missed anything or am doing this the completely wrong way then apologies, still trying to get my head round everything.

So my problem:
I have a table with first name, last name, office, and (car) CO2 emissions and am trying to get the name of the employees with the 3 best (lowest) CO2 emissions per office, in this case = GS. But am trying to keep everything tidy so have one big formula in a cell doing all the functions simultaneously. So far I have been able to do this but have hit a block because the 3rd best (lowest) employee is joint 3rd with 108 g/km and as a result the cell is only showing one name rather than the two.

Does anyone know what i need to do to fix this, or if it is possible? Formula and tables below. Hopefully this all makes sense but happy to answer any questions if not/it helps.

Thanks in advance!

(P.S. all names have been changed)

(Array) Formula:

{=(TEXTJOIN(",",TRUE,INDEX($B$11:$E$77,MATCH(1,($E$11:$E$77=SMALL(IF($D$11:$D$77="GS",$E$11:$E$77),3))*($D$11:$D$77="GS"),0),2)))}

This returns 'Ellis' but I need it to return 'Ellis,Parker' as both are the 3rd best CO2 emissions in the 'GS' office.

Table:
First NameLast NameOfficeCo2 Emission
OliverCaseyIN157
AidaCrawfordGS214
WilliamEllisGS108
NatalieArmstrongMD119
RosieBakerMD89
StellaBrooksIN105
OscarParkerGS108
NatalieMorrisIN115
AlenGibsonGS105
BriannaEvansMD111
AmberJonesNT133
MirandaArmstrongNT104
BrookeMasonGS133
MyraHillGS165
RyanHillMD117
RafaelGrantMD117
LuciaHillIN256
JuliaMasonGS128
EdwardBaileyWW169
AidenMurrayWW119
LilyReedLE112
KellanGibsonIN0
DarylSullivanIN138
DexterScottGS99
MartinRobertsMD127
MichelleEllisIN209
JustinWrightIN91
BradAllenGS120
RichardEllisIN134
ConnieHarperIN106
ValeriaBrownIN106
BrionyPerryGS124
CarlMorrisIN120
CarlosAdamsIN153
AprilClarkGS113
BrookeAlexanderIN129
BriannaColeIN146
PenelopeChapmanIN294
KevinDavisWW103
PaigeMitchellGS112
 
The expected results are Oscar Parker, Myra Hill, Kellan Gibson, Brooke Mason, Aida Crawford
First NameLast NameOfficeCo2 Emission
OscarParkerGS
0​
MyraHillGS
0​
KellanGibsonIN
0​
BrookeMasonGS
0​
AidaCrawfordGS
0​
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The expected results are Oscar Parker, Myra Hill, Kellan Gibson, Brooke Mason, Aida Crawford
So, this is also different in that you are looking for First Name and Last Name, not just Last Name?

Are all the results to be listed in a single cell as before, or one name per cell?

What about ties in this scenario? What is the expected result for this data?

Dlloyd15 2020-02-22 1.xlsm
BCDE
10First NameLast NameOfficeCo2 Emission
11OliverCaseyIN757
12AidaCrawfordGS0
13WilliamEllisGS108
14NatalieArmstrongMD119
15RosieBakerMD189
16StellaBrooksIN105
17OscarParkerGS50
18NatalieMorrisIN115
19AlenGibsonGS105
20BriannaEvansMD99
21AmberJonesNT133
22MirandaArmstrongNT104
23BrookeMasonGS0
24MyraHillGS50
25RyanHillMD117
26RafaelGrantMD117
27LuciaHillIN256
28JuliaMasonGS99
29EdwardBaileyWW169
30AidenMurrayWW119
31LilyReedLE112
32KellanGibsonIN99
33DarylSullivanIN138
34DexterScottGS99
35MartinRobertsMD127
5 lowest
 
Upvote 0
I would be looking for first and last name. The first name in one cell and the last name in the column beside it.
Thanks for clarifying about ties. In this case 0 is ranked 1 for the 5 people. Here is the screenshot for all of them. My data would be unsorted like the example above and there is no rank column.
Book1
K
15
Sheet2 (2)
 
Upvote 0
See below for XL2BB spreadsheet.
 
Last edited:
Upvote 0
Book1
ABCDEFGHI
5Expected Results
6
7RankFirst NameLast NameCo2 Emission
81OscarParker0
91MyraHill0
10Rank 1First NameLast NameOfficeCo2 Emission1KellanGibson0
111OscarParkerGS01BrookeMason0
121MyraHillGS01AidaCrawford0
131KellanGibsonIN02RosieBaker89
141BrookeMasonGS03DexterScott99
151AidaCrawfordGS04MirandaArmstrong104
162RosieBakerMD895StellaBrooks105
173DexterScottGS995JuliaMason105
184MirandaArmstrongNT1045AlenGibson105
195StellaBrooksIN105
205JuliaMasonGS105
215AlenGibsonGS105
22WilliamEllisGS108
23BriannaEvansMD111
24LilyReedLE112
25NatalieMorrisIN115
26RyanHillMD117
27RafaelGrantMD117
28NatalieArmstrongMD119
29AidenMurrayWW119
30MartinRobertsMD127
31AmberJonesNT133
32DarylSullivanIN138
33EdwardBaileyWW169
34LuciaHillIN256
35OliverCaseyIN757
Sheet2 (2)
 
Upvote 0
Since you said your data was unsorted, I have mixed them up.

G8 formula is copied across and down.

Dlloyd15 2020-02-22 1.xlsm
BCDEFGH
7First NameLast Name
8MyraHill
9AidaCrawford
10First NameLast NameOfficeCo2 EmissionBrookeMason
11MirandaArmstrongNT104KellanGibson
12EdwardBaileyWW169OscarParker
13StellaBrooksIN105RosieBaker
14AidenMurrayWW119DexterScott
15NatalieArmstrongMD119MirandaArmstrong
16MyraHillGS0StellaBrooks
17OliverCaseyIN757AlenGibson
18LilyReedLE112JuliaMason
19BriannaEvansMD111  
20MartinRobertsMD127  
21AidaCrawfordGS0
22RosieBakerMD89
23BrookeMasonGS0
24RafaelGrantMD117
25NatalieMorrisIN115
26DexterScottGS99
27AlenGibsonGS105
28WilliamEllisGS108
29JuliaMasonGS105
30KellanGibsonIN0
31LuciaHillIN256
32RyanHillMD117
33OscarParkerGS0
34DarylSullivanIN138
35AmberJonesNT133
5 lowest
Cell Formulas
RangeFormula
G8:H20G8=IF(ROWS(G$8:G8)>COUNTIF($E$11:$E$35,"<="&INDEX(SORT(UNIQUE($E$11:$E$35),1),5)),"",INDEX(SORTBY(B$11:B$35,$E$11:$E$35,1),ROWS(G$8:G8)))
 
Upvote 0
Absolutely brilliant. That's exactly what I'm looking for. :)(y)
 
Upvote 0
Actually, here is a better solution. Try this formula in cell G8 only. All the results should automatically "spill" into the required cells.

Dlloyd15 2020-02-22 1.xlsm
BCDEFGH
7First NameLast Name
8MyraHill
9AidaCrawford
10First NameLast NameOfficeCo2 EmissionBrookeMason
11MirandaArmstrongNT104KellanGibson
12EdwardBaileyWW169OscarParker
13StellaBrooksIN105RosieBaker
14AidenMurrayWW119DexterScott
15NatalieArmstrongMD119MirandaArmstrong
16MyraHillGS0StellaBrooks
17OliverCaseyIN757AlenGibson
18LilyReedLE112JuliaMason
19BriannaEvansMD111
20MartinRobertsMD127
21AidaCrawfordGS0
22RosieBakerMD89
23BrookeMasonGS0
24RafaelGrantMD117
25NatalieMorrisIN115
26DexterScottGS99
27AlenGibsonGS105
28WilliamEllisGS108
29JuliaMasonGS105
30KellanGibsonIN0
31LuciaHillIN256
32RyanHillMD117
33OscarParkerGS0
34DarylSullivanIN138
35AmberJonesNT133
5 lowest (2)
Cell Formulas
RangeFormula
G8:H18G8=FILTER(SORTBY($B$11:$C$35,$E$11:$E$35,1),SORTBY($E$11:$E$35,$E$11:$E$35,1)<=INDEX(SORT(UNIQUE($E$11:$E$35),1),5))
Dynamic array formulas.
 
Upvote 0
That formula works great. I love how the formula spills over. I used the formula
=SUMPRODUCT((J8>=$J$8:$J$18)/COUNTIF($J$8:$J$18,$J$8:$J$18)) to rank the data.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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