Looks like I gave in too fast.
7 day running total: =Sum(Filter(D2:D8,A2:A8<=A8,A2:A8>A8-7))
Filter returns a range of data, filtered based on multiple (can have more than 2 conditions). In the case I'm returning D2:D8
(my count column) filtered where A2:A8
(my date column) is less than the current date (A8
) and greater than the current date - 7 days. Stick this in the 7th cell, and drag the cell out to manipulate the formulae into the following cells.
Then for 7 day running average (assuming the above in F
) G8 = F8 / 7
:)
For a conditional running average, assuming all entries in A2:A are grouped:
=ArrayFormula(IFERROR((SUMIF(ROW(A2:A),"<="&ROW(A2:A),B2:B)-HLOOKUP(0,SUMIF(ROW(A2:A),"<"&ROW(A2:A),B2:B),MATCH(A2:A,A2:A,0),0))/(ROW(A2:A)-MATCH(A2:A,A2:A,0)-ROW(A2)+2)))
Before the update to the newest version of Sheets a number of months ago, it would have generally been advised to use MMULT for these sort of "conditional running total" problems:
=ArrayFormula(IF(LEN(A2:A),MMULT((ROW(A2:A)>=TRANSPOSE(ROW(A2:A)))*(A2:A=TRANSPOSE(A2:A)),--B2:B)/MMULT((ROW(A2:A)>=TRANSPOSE(ROW(A2:A)))*(A2:A=TRANSPOSE(A2:A)),SIGN(ROW(A2:A))),))
This solution also has the added benefit that the A2:A column needn't be grouped, nor sorted. However, in the newest version, the MMULT solution will break when the referenced range reaches 3163 rows. It appears to be because the 2D array formed by MMULT will tip over 10 million elements (square root of 10 million = 3162.278...).
The first solution shouldn't suffer this limitation, however it will probably still get very slow when referencing a few thousand rows.
Best Answer
demo spreadsheet of running total
alternative: https://wamoyo.github.io/amortization/