问题
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