How to use AVERAGEIFS within ARRAYFORMULA

余生长醉 提交于 2020-01-05 04:11:26

问题


I am trying to use AVERAGEIFS inside ARRAYFORMULA. Looking at other questions, I have come to the conclusion that it is not possible without using QUERY function.

My intention is to average the values of a column whenever they share the same ID.

I think this question comes pretty close to what I need, but I haven't been able to replicate and adapt its solution on my own sheet.

In this sheet I show the result I expect (I got it by dragging the formula). I've also reviewed the Query Language Reference, unsuccessfully.

Thanks a lot for your time and effort.


回答1:


So the formula should be

=ArrayFormula(iferror(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)))

Note that if there were any text values in the points column, this would still return a result (because count would be greater than zero) - you could instead use

=ArrayFormula(if(isnumber(B2:B),(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)),""))

If you had a mixture of rows with text and rows with numbers for any ID, this would return a smaller result than the avg or average formula. This is a limitation of this method. You can't put an extra condition in (that column B has to contain a number) because you would need countifs and countifs isn't array-friendly. It still seems strange that AFAIK countif and sumif are the only functions out of this family that are array-friendly while countifs, sumifs, averageif etc. are not.




回答2:


you can do:

=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A; QUERY(A2:B; "select A,avg(B) group by A"); 2; )))



来源:https://stackoverflow.com/questions/58542625/how-to-use-averageifs-within-arrayformula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!