I'm trying to use an arrayformula to sum weekly values. I have a table like:
A B C
date | value | weekly total
---------------------------------
2016/08/28 | 5 |
2016/08/29 | |
2016/08/30 | 5 |
2016/08/31 | 5 |
2016/09/01 | 5 |
2016/09/02 | |
2016/09/03 | | <should be 20>
I want the C column to calculate the sum of the B column for the past week each Saturday.
I have =ArrayFormula(IF( EQ(weekday(A2:A),7), SUM(B2:B), ""))
I would think there should be a simple way to tell SUM to take from 6 rows back to the current row, but I haven't found anything.
Another option is:
=ArrayFormula(IF( EQ(weekday(A2:A),7), SUMIF(WEEKNUM(A2:A),WEEKNUM(A2:A),B2:B), ""))
but that breaks when there's more than one year on the sheet.
Any ideas?
Best Answer
Phew that actually took me a while to work out. Your formula in cell C9 is:
=if(weekday(A9)=7,SUM(INDIRECT("R[-6]C[-1]",FALSE):INDIRECT("RC[-1]",FALSE)),"")
You can copy that all the way up/down column C.
You end up with this: