SOLVED

How do I pick the category of the smallest value in each row?

Copper Contributor

Hello, I'm working with a panel data like this. I want to pick the category name (in row 2) of the smallest value in each row. I know how to pick the smallest value of each row, but don't know how can I have the category name as the output in column AX. 

 

Thank you so much for helping! 

 

MyUsername1024_0-1677919547001.png

Device and OS platform: Windows 10

Excel product name and version number: 

Microsoft® Excel® 2016 MSO (Version 2301 Build 16.0.16026.20196) 64-bit

 

2 Replies
best response confirmed by MyUsername1024 (Copper Contributor)
Solution

@MyUsername1024 

=INDEX($AP$1:$AW$1,MATCH(MIN(AP2:AW2),AP2:AW2,0))

You can try this formula with the data of the example.

category for smallest value of each row.JPG 

@MyUsername1024 

Increasingly my advice to users of legacy Excel is replace it as soon as you can.  In this case the formula is not so different and wouldn't justify the change,

 

= BYROW(values, LAMBDA(v, XLOOKUP(MIN(v), v, Categories)))

 

but the good thing is that the categories are returned as an array, so it is possible to build upon solution without spreading the calculation across ranges.  For example one could ask 'how many times does each category appear as the smallest and which occurs most frequently?'

 

= LET(
    minCategory,  BYROW(values,   LAMBDA(v, XLOOKUP(MIN(v), v, Categories))),
    Occurences,   MAP(Categories, LAMBDA(c, SUM(SIGN(minCategory=c)))),
    mostFrequent, FILTER(Categories, Occurences=MAX(Occurences)),
    TEXTJOIN(", ",,mostFrequent)
  )

 

image.png

The objective is to develop a solution in the most coherent and readable form possible.

1 best response

Accepted Solutions
best response confirmed by MyUsername1024 (Copper Contributor)
Solution

@MyUsername1024 

=INDEX($AP$1:$AW$1,MATCH(MIN(AP2:AW2),AP2:AW2,0))

You can try this formula with the data of the example.

category for smallest value of each row.JPG 

View solution in original post