Let say I have a dataset of car selling. I want to rank each car product for its category. Right now, I can get this by using this formula.
=rank(C2,filter(C$2:$C,B$2:$B=B6))
This formula works fine, except that I have to copy this for each row. I see an array formula, but I can not figure out how to use it.
Here is the Sample Workbook Car Selling
Try
=arrayformula(iferror(VLOOKUP(row(B2:B),{sort({row(B2:B),B2:C},2,1,3,0),row(B2:B)},4,false)-MATCH((B2:B),QUERY({sort({B2:C},1,1,2,0)},"select Col1"),0)))
1- the key to the solution is to play with a virtual database sorted by cotegory and value where I add the current row after sorting
{row(B2:B),B2:C},2,1,3,0),row(B2:B)}
I will search within this virtual database for a "global ranking"
=arrayformula(VLOOKUP(row(B2:B),{sort({row(B2:B),B2:C},2,1,3,0),row(B2:B)},4,false))
2- the second step is to work with the only category within the same sorting process
QUERY({sort({B2:C},1,1,2,0)},"select Col1")
and retrieve the first line where the category appears
=arrayformula(iferror(MATCH((B2:B),QUERY({sort({B2:C},1,1,2,0)},"select Col1"),0)))
3- and at the end you subtract the two values
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.