Find the nth largest value and return the value in another column

gberg

Board Regular
Joined
Jul 16, 2014
Messages
180
Office Version
  1. 365
Platform
  1. Windows
I have a table and want to find the nth largest value but then return the result from a different column in the same row the nth value is located in. I have a large table so this is a small example


Object#nResult
Orange
54​
1Pineapple
Apple
35​
2Pear
Pear
68​
3Orange
Grape
1​
Pineapple
548​

The table would be "Object" and "#" (Table A) and the results would be the N and Results


I would want to look for the largest value in the "#" column and return the result from the "Object" column. In this case it would be Pineapple with 548. It would go down the list and look for the second largest value (68 / Pear) and so on.

Thanks for any help you can give me.

Greg
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Perhaps this:

Book1
ABCDE
1Object#nResult
2Orange541Pineapple
3Apple352Pear
4Pear683Orange
5Grape1
6Pineapple548
Sheet1
Cell Formulas
RangeFormula
E2:E4E2=INDEX(SORTBY($A$2:$A$6,$B$2:$B$6,-1),D2)
 
Upvote 0
dreid1011,
That worked, but I'm an idiot and forgot that there are other conditions that need to be met. The formula would need to look at multiple columns for other conditions.

ObjectIn StockExpired#nResult
OrangeYesNo
54​
1Orange
AppleYesNo
35​
2Apple
PearYesYes
68​
3Grape
GrapeYesAlmost
1​
PineappleNoNo
548​


The "In Stock" column would need to be "Yes" and the "Expired" column could not equal "Yes". I have updated the results based on this additional criteria. Sorry about leaving this part out.

Thanks,

Greg
 
Upvote 0
Alright, try this, I also changed the #s to test because your sample just so conveniently had them in the desired order in the original list:

Book1
ABCDEFGH
1ObjectIn StockExpired#nResultResult 2
2OrangeYesNo541PineappleGrape
3AppleYesNo772GrapeApple
4PearYesYes683AppleOrange
5GrapeYesAlmost99
6PineappleNoNo548
Sheet1
Cell Formulas
RangeFormula
G2:G4G2=INDEX(SORTBY($A$2:$A$6,$D$2:$D$6,-1),F2)
H2:H4H2=LET(n,($B$2:$B$6="Yes")*($C$2:$C$6<>"Yes"),INDEX(SORTBY(FILTER($A$2:$A$6,n),FILTER($D$2:$D$6,n),-1),F2))
 
Upvote 0
Solution
Another option
Fluff.xlsm
ABCDEFG
1ObjectIn StockExpired#3Result
2OrangeYesNo541Orange
3AppleYesNo352Apple
4PearYesYes683Grape
5GrapeYesAlmost1
6PineappleNoNo548
7
Data
Cell Formulas
RangeFormula
F2:F4F2=SEQUENCE(F1)
G2:G4G2=TAKE(SORT(FILTER(A2:D100,(B2:B100="yes")*(C2:C100<>"yes")),4,-1),F1,1)
Dynamic array formulas.
 
Upvote 0
Thank you both! Each solution works great but now I don't know which to use? Is there a benefit to using the Dynamic array over the LET formula or vise versa? You both make this look so easy!

Thanks,

Greg
 
Upvote 0
Unless you have massive amounts of data, I doubt there's much difference in speed.
So use the one you prefer.
 
Upvote 0
I actually do have a massive amount of data. 36,000 plus rows x 24 columns. Probably better suited for a database, but I don't know Access so I stick with Excel
 
Upvote 0
In that case try both solutions on the real data & see if there is any difference in speed.
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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