我将在本文底部发布指向电子表格的链接。
我正在尝试计算介于日期范围之间的一列数字的平均值。下面的公式有效,但是我必须将其拖到列中,我希望它是一个数组,以便它自动更新。
=iferror(averageifs(B$2:B,A$2:A,">="&C2,A$2:A,"<="&D2),1)
所以我将其创建为数组,如下所示:
=iferror(ArrayFormula(averageifs(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1
但是它在第一个单元格之后停止。因此,我将平均函数分解为求和与计数以进行除法。
count数组使用以下公式工作:
=iferror(ArrayFormula(countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
但是sum数组甚至都没有超过第一个单元格:
=iferror(ArrayFormula(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
组合超出第一个单元格,但计算全部变为零:
=ArrayFormula(iferror(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)/countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D),1))
我想要实现的是上个月的平均值。
如果有人可以帮助我,我将非常感激!
https://docs.google.com/spreadsheets/d/1XhoLl5hB-MpXFz9VS2aLqJOWbXk1d_7apnwKWFdDUlg/edit?usp=sharing
答案 0 :(得分:0)
您试图无缘无故地应用一些具有很多重复值的奇怪的结构逻辑。基本上,您需要这样做:
=ARRAYFORMULA(QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
order by avg(Col2) desc
label avg(Col2)''", 0))
但是如果您确实需要:
=ARRAYFORMULA(IF(LEN(A2:A),
IFERROR(VLOOKUP(TEXT(DATE(YEAR(A2:A), MONTH(A2:A)-1, 1), "yyyy-mmm"),
QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1", 0), 2, 0), 0), ))