I'm using PYSPARK and I'm trying to make a cumulative sum of the last 3 months from a specific month:
Example:
Month Value
Jan/19 1
Feb/19 0
Mar/19 4
Apr/19 5
May/19 0
Jun/19 10
So the cumulative sum for each month on the previous months will be:
Month Value
Jan/19 1
Feb/19 1 + 0 = 1
Mar/19 1+0+4 = 5
Apr/19 0+4+5 = 9
May/19 4+5+0 = 9
Jun/19 5+0+10 = 15
I'm pretty sure that I need to use window and partition functions but I have no idea how to set up this.
Can anyone help me on this?
Thanks