Array Formula with AverageIF of a row

大兔子大兔子 提交于 2021-01-29 08:35:44

问题


I have a formula in a Google Sheet that is averaging the values in a row...

=AVERAGEIF(A2:L2,"<>0")

Simple, right?

However, I cannot figure out how to get the ARRAYFORMULA to work for this.

=ARRAYFORMULA(AVERAGEIF(A2:L,"<>0")

That formula only averages all of the cells in the range, instead of returning the average for each row. What am I missing?


回答1:


you were close. try:

=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:L),
 "select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
 "avg(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&"")), 
 "select Col2"))

then to add <>0 you need:

=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:L),
 "select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
 "avg(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&
 "where "&TEXTJOIN(" and ", 1, IF(LEN(A2:A), 
 "not Col"&ROW(A2:A)-ROW(A2)+1&"=0", ))&"")), 
 "select Col2"))



来源:https://stackoverflow.com/questions/59218199/array-formula-with-averageif-of-a-row

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