Search code examples
excelsumaverage

Average of BYROW and BYCOL results in Excel


I have a 20x20 table for which I applied the BYROW and BYCOL functions to get the row totals and column totals.

Function 1:

B22=BYROW(B2:U21,LAMBDA(row,SUM(row)))

Function 2:

V2=BYCOL(B2:U21,LAMBDA(column,SUM(column)))

How can I achieve the following steps?

  1. I want to find the average of Row 1 total and Column 1 total and repeat this for all rows and columns resulting in an array of 20 values.
  2. I want to use LARGE(Array, k) function to find the top 10 values of the values stored in the array in step 1.

Solution

  • Just put them all together:

    =TAKE(SORT(BYROW(HSTACK(TRANSPOSE(B22#),V2#),LAMBDA(RW,AVERAGE(RW))),1,-1),10)
    

    enter image description here


    As stated by @user11222393, to get the row/column from where the value comes:

    =TAKE(SORT(HSTACK(BYROW(HSTACK(TRANSPOSE(B22#),V2#),LAMBDA(RW,AVERAGE(RW))),SEQUENCE(COUNT(B22#),1,1,1)),1,-1),10)
    

    Since relative row and relative column number are the same it will return a single relative number.

    enter image description here


    If you want it a little prettier:

    =TAKE(SORT(HSTACK(BYROW(HSTACK(TRANSPOSE(B22#),V2#),LAMBDA(RW,AVERAGE(RW))),LET(r,SEQUENCE(COUNT(B22#),1,2,1),"CLM: "&CHAR(65+r)&" rw: "&r)),1,-1),10)
    

    enter image description here