Most likely you'll use the Window_Sum table calculation. The code will look something like this:
I've attached a workbook to demonstrate. The way you end up using the table calculation might depend on the actual structure of your data. Please let me know if you have any questions. I'd be happy to answer them!
Window_Sum.twbx.zip 11.4 KB