Dynamic rolling sum in excel

176 views Asked by At

How can I calculate the rolling sum of a column based on another column?

Example:

Input data are the first 3 columns in the below table. The result column that I am trying to get is highlighted in green. I want to get the dynamic sum of 'Daily sales' based on the corresponding 'No of days' given.

enter image description here

3

There are 3 answers

0
VanodyaPerera On BEST ANSWER

This formula worked. Add the 'OFFSET' function inside the 'SUM' function to input the dynamic array.

enter image description here

0
Harun24hr On

If you are on Microsoft-365 then could try the following formula for dynamic spill results.

=MAP(C2:C13,LAMBDA(x,SUM(OFFSET(x,0,-1,x))))

enter image description here

0
JvdV On

Assuming there is sample data missing, hence the lower rows will yield different results, here is yet another alternative:

enter image description here

Formula in D1:

=MAP(B1:B12,C1:C12,LAMBDA(x,y,SUM(x:INDEX(B:B,ROW(x)+y-1))))

Or just don't use LAMBDA() at all, but a simple SUMIFS():

=SUMIFS(B1:B12,A1:A12,">="&A1:A12,A1:A12,"<="&A1:A12+C1:C12-1)