Home > Software engineering >  Calculate the average of sets of cells satisfying a certain criterion (AVERAGEIF)
Calculate the average of sets of cells satisfying a certain criterion (AVERAGEIF)

Time:11-25

This is my Items sheet

enter image description here

And this is my Values sheet

enter image description here

As can be seen from the table, alfa is associated with 20 40 60 80, beta with 30 40 70 80 and gamma with 50 60 70 80.

In the Items sheet in cell B1 (next to the first item) I would like a formula (Arrayformula or alike) generating the average value for each item. In my example it should be:

alfa -> 50 (that is: (20 40 60 80)/4 = 200/4)  
beta -> 55 (that is: (30 40 70 80)/4 = 220/4)  
gamma-> 65 (that is: (50 60 70 80)/4 = 260/4)  

So the final result should be:

enter image description here

This is my googlesheet: enter image description here


update

=IFERROR(BYROW(A1:INDEX(A:A, MAX(ROW(A:A)*(A:A<>""))), 
 LAMBDA(x, INDEX(QUERY(SPLIT(FLATTEN(
 FILTER(Values!A:C, Values!D:D<>"")&"​"&
 FILTER(Values!D:D, Values!D:D<>"")), "​"),   
 "select avg(Col2) where Col1 = '"&x&"'"), 2))))
  • Related