Find the top 3 items in an array, with priority given to those higher on a list in the event of tie

痴心易碎 提交于 2021-01-29 13:54:06

问题


My list has only numbers, with a corresponding name to each score in each row. I am looking for a formula to draw lookup the 1st, 2nd and 3rd names with the corresponding rank. However, in the event of ties, i would like still like to draw the largest number, with preference for names higher on the list.

the list


回答1:


In cell E1 insert following formula and then copy down.

=IFERROR(INDEX($A$1:$A$15,SMALL(IF($B$1:$B$15=MAX($B$1:$B$15),ROW($A$1:$A$15),10^7),ROWS($A$1:A1))),"")

Note: This is array formula so it needs to be committed by using CTRL+SHIFT+ENTER simultaneously. If done correctly Excel will wrap formula with braces.

Here's a non-CSE AGGREGATE based formula (based on @Naresh Bhople's suggestion)

=IFERROR(INDEX($A$1:$A$15,AGGREGATE(15,6,IF($B$1:$B$15=MAX($B$1:$B$15),ROW($A$1:$A$15),10^7),ROWS($A$1:A1))),"")

Following is not array formula after removing if condition. Referred this link

=IFERROR(INDEX($A$1:$A$15,AGGREGATE(15,6,(($B$1:$B$15=MAX($B$1:$B$15))/($B$1:$B$15=MAX($B$1:$B$15))*ROW($A$1:$A$15)),ROWS($A$1:A1))),"")

Edit2:

Following is an unwieldy approach but it works with this data and limited testing I did, it is an array formula.

=INDEX($A$2:$A$15,MATCH(SMALL(NPV(-RANK.EQ($B$2:$B$15,$B$2:$B$15)%,$B$2:$B$15)*100+ROW($B$2:$B$15),ROWS($A$1:A1)),NPV(-RANK.EQ($B$2:$B$15,$B$2:$B$15)%,$B$2:$B$15)*100+ROW($B$2:$B$15),0))



来源:https://stackoverflow.com/questions/61967833/find-the-top-3-items-in-an-array-with-priority-given-to-those-higher-on-a-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!