0

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

VanodyaPerera
  • 137
  • 1
  • 1
  • 10

3 Answers3

2

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)
JvdV
  • 70,606
  • 8
  • 39
  • 70
1

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

enter image description here

VanodyaPerera
  • 137
  • 1
  • 1
  • 10
1

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

Harun24hr
  • 30,391
  • 4
  • 21
  • 36