Return column header for highest, 2nd highest, 3rd highest etc value

junkforhr

Board Regular
Joined
Dec 16, 2009
Messages
115
Office Version
  1. 365
Platform
  1. Windows
I have a dataset (reduced mock version below).

What I'm trying to do is return the column head for the highest count for site. As an example, Site 1 has the highest count of 15.455, so I'd like Type A returned. The 2nd highest value for Site 1 is 9,708 and this would return Type E. I have included a desired outcome table below.

The actual data will have 500 Sites and 100 columns, but I'm only looking for the Top 15 Types.

I had a go using the large formula to return the top nth for each site, but am at a lost how to use this in a lookup.

Mock table below
SiteType AType BType CType DType E
Site1
9,589​
15,455​
3,131​
8,989​
9,708​
Site2
25,140​
13,014​
15,774​
25,302​
23,295​
Site3
22,683​
6,635​
16,905​
19,133​
23,445​
Site4
21,917​
1,812​
19,088​
9,464​
3,305​

Desired result

SiteHighest Type2nd Highest Type3rd Highest Type
Site1Type BType EType A
Site2Type DType AType E
Site3Type EType AType D
Site4Type AType CType D
 

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.
  1. Is it possible that two (or more) columns in the same row in the top table could have exactly the same values?
  2. Can we assume that the Sites in the first column will be in exactly the same order in each table?
 
Upvote 0
  1. Is it possible that two (or more) columns in the same row in the top table could have exactly the same values?
  2. Can we assume that the Sites in the first column will be in exactly the same order in each table?
Hi Peter,
Question 1: Yes it is possible, but highly unlikely.
Question 2: Yes
 
Upvote 0
Given "Yes" to question 2, this might do until Peter returns with a more elegant response ;)
Book1
ABCDEF
1SiteType AType BType CType DType E
2Site19,58915,4553,1318,9899,708
3Site225,14013,01415,77425,30223,295
4Site322,6836,63516,90519,13323,445
5Site421,9171,81519,0889,4643,305
6
7Highest Type2nd Highest Type3rd Highest Type
8Site1Type BType EType A
9Site2Type DType AType E
10Site3Type EType AType D
11Site2Type AType CType D
Sheet1
Cell Formulas
RangeFormula
B8:B11B8=INDEX($B$1:$F$1,0,MATCH(LARGE($B2:$F2,1),$B2:$F2,0))
C8:C11C8=INDEX($B$1:$F$1,0,MATCH(LARGE($B2:$F2,2),$B2:$F2,0))
D8:D11D8=INDEX($B$1:$F$1,0,MATCH(LARGE($B2:$F2,3),$B2:$F2,0))
 
Upvote 0
Question 1: Yes it is possible, but highly unlikely.
Given that, these are the best I could come up with so far

23 06 22.xlsm
ABCDEF
1SiteType AType BType CType DType E
2Site19,70815,4553,1318,9899,708
3Site225,14013,01415,77425,30223,295
4Site322,6836,63516,90519,13323,445
5Site421,9171,81219,0889,4643,305
6
7
8SiteHighest Type2nd Highest Type3rd Highest Type
9Site1Type BType AType E
10Site2Type DType AType E
11Site3Type EType AType D
12Site4Type AType CType D
Top 3
Cell Formulas
RangeFormula
B9:B12B9=INDEX($1:$1,AGGREGATE(15,6,COLUMN($B$1:$F$1)/($B2:$F2=LARGE($B2:$F2,COLUMNS($B:B))),1))
C9:C12C9=INDEX($1:$1,AGGREGATE(15,6,COLUMN($B$1:$F$1)/($B2:$F2=LARGE($B2:$F2,COLUMNS($B:C))),1+(INDEX(2:2,MATCH(B9,$1:$1,0))=LARGE($B2:$F2,COLUMNS($B:C)))))
D9:D12D9=INDEX($1:$1,AGGREGATE(15,6,COLUMN($B$1:$F$1)/($B2:$F2=LARGE($B2:$F2,COLUMNS($B:D))),1+(INDEX(2:2,MATCH(C9,$1:$1,0))=LARGE($B2:$F2,COLUMNS($B:D)))+(INDEX(2:2,MATCH(B9,$1:$1,0))=LARGE($B2:$F2,COLUMNS($B:D)))))


If the answer to Q1 was "No" then you could use the 3 formulas that Kevin posted or this variation of it which can be copied across and down

23 06 22.xlsm
ABCDEF
1SiteType AType BType CType DType E
2Site19,58915,4553,1318,9899,708
3Site225,14013,01415,77425,30223,295
4Site322,6836,63516,90519,13323,445
5Site421,9171,81219,0889,4643,305
6
7
8SiteHighest Type2nd Highest Type3rd Highest Type
9Site1Type BType EType A
10Site2Type DType AType E
11Site3Type EType AType D
12Site4Type AType CType D
Top 3
Cell Formulas
RangeFormula
B9:D12B9=INDEX($B$1:$F$1,MATCH(LARGE($B2:$F2,COLUMNS($B:B)),$B2:$F2,0))
 
Upvote 1
Solution

Forum statistics

Threads
1,223,230
Messages
6,170,883
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