cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
chadyoder
Level I

Cumulative sum by grouping and rolling values formula??

I have a data set with groups, days and visits on those days.  I would like to get a rolling sum of every 3 days, so at day 3 the value would be sum of day 1, 2, 3, but on day 4 the value is the sum of days 2, 3,4.   And do this by group.  I know I can use the cumulative sum by group, but that returns the sum each day, so day 4, would be the sum of all 4 days, but I would like the first day to drop off at that point.   Any help would be great.

 
GroupDayVisits
110
120
139
1410
1514
1622
1711
1812
212
224
231
243
252
262
273
281
2 REPLIES 2
jthi
Super User

Re: Cumulative sum by grouping and rolling values formula??

One option would be to use Col Moving Average and multiply that with the amount of days

Col Moving Average(:Visits, 1, 2, 0, 1, :Group) * 3

jthi_0-1666724887386.png

 

-Jarmo
txnelson
Super User

Re: Cumulative sum by grouping and rolling values formula??

Here is a one way of handling it

txnelson_0-1666725281346.png

avg = Col Moving Average( :Visits, weighting = 1, before = 2, :Group );
count = Col Cumulative Sum( 1, :Group );
If( count >= 3, avg * 3, . );

 @jthi has the simpler option.....I assumed Col Moving Average gave responses when n was less than 3. 

Jim