Skip to main content
Answer

Moving sum fixed start date, dynamic end date

  • May 27, 2022
  • 7 replies
  • 478 views

Marina
Wallflower
Forum|alt.badge.img+1

Hello! I would like to calculate a movingsum formula where the starting month is always fixed (eg Jun 18) but the last month is always the current month. So for Mar 22 I would like the cumulative sum from Jun 18 to Mar 22 but for Apr 22 I would like the sum from Jun 18 to Apr 22. How can I do this? 

Best answer by Nathan

Sorry I wrote it incorrectly:

 

cumulate(metric[filter:Month.'Start Date'>= DATE(2028,01,01)],Month)

In terms of dimensions, all you need is for your source metric to have the Month dimension

7 replies

MKohli
Master Author
Forum|alt.badge.img+9
  • Master Author
  • May 27, 2022

Does your data start on Jun 18?

You can use the CUMULATE function to keep a rolling tab of the total

 

 


Marina
Wallflower
Forum|alt.badge.img+1
  • Author
  • Wallflower
  • May 27, 2022

My data start on Jan 15 but maybe I could create a metric to make zero all data before Jun 18 so that CUMULATE function is based on this one. However even when I try to do CUMULATE (metric 1, metric 2)  where metric 1 is the free cash flow & metric 2 the month, from month 1 it brings a huge amount. When trying to put the BY dimension it produces an error. Is there any advice when using this formula how we should be handling dimensions?


Nathan
Employee
Forum|alt.badge.img+12
  • Employee
  • May 30, 2022

you could try like this:

 

cumulate(metric[filter:Month.Start Date >= DATE(2028,01,01),Month]

 

ps: would be better to put the date in a metric itself


Nathan
Employee
Forum|alt.badge.img+12
  • Employee
  • May 30, 2022

try to do this formula in the playground so you’ll see the dimensions being computed 


Marina
Wallflower
Forum|alt.badge.img+1
  • Author
  • Wallflower
  • May 30, 2022

Hi @Nathan thanks for the advice! I try to do it exactly as you say and I get Syntax error: cannot validate formula. Is there any particular to watch out in terms of the dimensions in my metrics? Start date is a property of my month dimension. So what date do you suggest to put in a metric itself?


Nathan
Employee
Forum|alt.badge.img+12
  • Employee
  • Answer
  • May 30, 2022

Sorry I wrote it incorrectly:

 

cumulate(metric[filter:Month.'Start Date'>= DATE(2028,01,01)],Month)

In terms of dimensions, all you need is for your source metric to have the Month dimension


Nathan
Employee
Forum|alt.badge.img+12
  • Employee
  • June 3, 2022

@Marina did it work ?