I would like to calculate the average of the previous N-elements in a column and return an array. The output should be something like this for the last 3-elements on column B
, column C
shows the corresponding formula.
In my real problem, I need to return the result using an arrayformula
for the entire column. Column D
shows the formula for computing the average for non-empty rows, but I am not able to return the result considering the subset of the last three.
The following question: average the previous 5 cells that have values addressed a similar problem, but the result is not returned as an array. If I adapt the formula in Column D
, with the solution from the question, I don't the expected result:
=ARRAYFORMULA(if(NOT(ISBLANK(A:A)),
Average(Filter(Sort(A:A,If(A:A="",0,Row(A:A)),false),
Row(A:A)<3)),))
I don't get the expected result, the result is 5.5
for all non-empty rows.