Return Column heading in table, after looking up row and values in row

51 views Asked by At

I have the table below. I want to lookup the column header a number is between numbers based on the name in column A. So, if I look up "Dog" and "3.5" then I want it to return "B". The best formula I have come up with is

=INDEX(L1:M6,COLUMN(INDEX(A1:G5,MATCH(J2,A1:A5,0),MATCH(J3,B2:G2,-1))),2)

However, it's not working great. First, I had to create a separate table to indicate the column returned to get the column header. Also, I can't figure out how to make it change the row it looks the number in. Third, i can only make it work using the number in the row as the upper bound ex. "3.5" returns "#N/A" instead of "B".

enter image description here

=INDEX(L1:M6,COLUMN(INDEX(A1:G5,MATCH(J2,A1:A5,0),MATCH(J3,B2:G2,-1))),2)

I want to return "B", not "#N/A". Also I want it not have to rely on the first index function. Ideally the formula looks something like this?

=INDEX(A1:G5,MATCH(J2,A1:A5,0),MATCH(J3,B2:G2,-1))
1

There are 1 answers

1
Mayukh Bhattacharya On BEST ANSWER

Try using XLOOKUP() function here:

enter image description here


=XLOOKUP(J3,XLOOKUP(J2,A2:A5,B2:G5),B1:G1,,1,-1)