This is what my data looks like. The rightmost column is my Desired Column.
Name EventType EventDate SalesAmount RunningTotal Runningtotal(prior365Days)
John Email 1/1/2014 0 0 0
John Sale 2/1/2014 10 10 10
John Sale 7/1/2014 20 30 30
John Sale 4/1/2015 30 60 50
John Webinar 5/1/2015 0 60 50
Tom Email 1/1/2014 0 0 0
Tom Sale 2/1/2014 15 15 15
Tom Sale 7/1/2014 10 25 25
Tom Sale 4/1/2015 25 50 35
Tom Webinar 5/1/2015 0 50 35
I am just trying to get the running total of SalesAmount for each name in the last 365 days window. For the general "RunningTotal" column I used:
df<- df%>%
group_by (Name)%>%
mutate(RunningTotal = cumsum(SalesAmount))
But I dont know how to get the running total only in the last 365 day window.Kindly help. Your help is sincerely appreciated!