Search code examples
google-sheetsgoogle-sheets-formulaaverageflattengoogle-query-language

Get average of last 4 cells Google Sheets


I am trying to figure out how to find the average of the last 4 columns. Every column in yellow Fame is the score, and then Attacks is how many attacks used to get that score.

So essentially, it would need to add up the last 4 Fame columns, and divide it by the sum of the last 4 Attacks columns.

Example

For the first row (row 3), the final output would do this calculation:

(3500+2700+3250+3300) / (16+12+16+16) = 212.5

Example 2

For the second row (row 4), the final output would do this calculation:

(2850+3500) / (16+16) = 198.4

enter image description here

Any help is greatly appreciated! Thanks!


Solution

  • from right to left try:

    =SUM(SPLIT(REGEXEXTRACT(TEXTJOIN(" ", 1, FILTER(D3:3, 
     MOD(COLUMN(D3:3), 2)=0)), "\d+ \d+ \d+ \d+$"), " "))/
     SUM(SPLIT(REGEXEXTRACT(TEXTJOIN(" ", 1, FILTER(D3:3, 
     MOD(COLUMN(D3:3)-1, 2)=0)), "\d+ \d+ \d+ \d+$"), " "))
    

    enter image description here


    update:

    from left to right use:

    =INDEX(QUERY(QUERY(IFERROR(SPLIT(TRIM(FLATTEN(QUERY(TRANSPOSE(D3:6),,9^9))), " ")*1), 
     "select (Col1+Col3+Col5+Col7)/(Col2+Col4+Col6+Col8)"), "offset 1", 0))
    

    enter image description here