2

I have the following matrix.

enter image description here

The output I want to receive is.

enter image description here

I have implemented LARGE() function to find the top 3 values. I have tried implementing INDEX() and MATCH() functions in one formula to receive the above output but was unsuccessful. How can we get the above output in excel?

2
  • 2
    Just to be sure, values are not unique and 2 same values with different coordinates are possible? Commented Aug 9, 2023 at 22:12
  • 2
    I think your result table has a typo for 73 the RowID will be 5 and not 3 Commented Aug 9, 2023 at 22:24

2 Answers 2

4

Try using the following formula:

enter image description here


• Formula used in cell H1

=LET(
     a,TOCOL(B2:F6),
     b,TOCOL(IFNA(A2:A6,SEQUENCE(,ROWS(B2:F6)))),
     c,TOCOL(IFNA(B1:F1,SEQUENCE(ROWS(B2:F6)))),
     d,TAKE(SORT(HSTACK(a,b,c),1,-1),3),
     VSTACK({"Rank","Value","RowID","ColID"},
     HSTACK(SEQUENCE(ROWS(d)),d)))

This is another alternative formula but the number of bytes is more as well it uses LAMBDA( ) helper function BYROW( )

=LET(
     a,A1:F6,
     b,TAKE(SORT(TOCOL(DROP(a,1,1)),,-1),3),
     c,BYROW(b,LAMBDA(m,CONCAT(REPT(DROP(a,1,-5)&"|"&TAKE(a,1,-5),m=DROP(a,1,1))))),
     d,HSTACK(SEQUENCE(ROWS(b)),b,TEXTBEFORE(c,"|"),TEXTAFTER(c,"|"))+0,
     VSTACK({"Rank","Value","RowID","ColID"},d))

Bit less bytes than the earlier one:

=LET(
     a,A2:A6,
     b,B1:F1,
     c,B2:F6,
     d,TAKE(SORT(TOCOL(c),,-1),3),
     e,SEQUENCE(ROWS(d)),
     HSTACK(VSTACK("Rank",e),REDUCE({"Value","RowID","ColID"},d,LAMBDA(x,y,
     VSTACK(x,HSTACK(y,CONCAT(REPT(a,y=c)),CONCAT(REPT(b,y=c)))+0)))))
2
  • In this case how can we exclude the diagonal elements?
    – vp_050
    Commented Aug 10, 2023 at 14:21
  • @vp_050 have you posted a question for this ? Commented Aug 10, 2023 at 15:14
2

Here is an alternative:

enter image description here

Formula in H1:

=VSTACK({"Rank","Value","RowID","ColID"},HSTACK({1;2;3},TAKE(SORT(--TEXTSPLIT(TEXTAFTER("|"&TOCOL(B2:F6&"|"&A2:A6&"|"&B1:F1),"|",{1,2,3}),"|"),,-1),3)))
1
  • If any of the cells are blank or there are NAs, how can we ignore these cells in the above formula?
    – vp_050
    Commented Aug 24, 2023 at 18:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.