Moving Average in Custom Timescale


Good Day!!


I have a scenario where I'm trying to calculate the moving average from actuals in Custom Day time scale. In a module, I have sales data to be uploaded, from the sales data I have to calculate the moving avg of 90 days at the day level. Dimension in the module Article, Custom Day scale. Line Item -Sales  Qty, Sales Value.



I tried using the formula -

Line item 1- CUMULATE(Sales Qty, FALSE, Custom Day)) / 90

Line Item 2- 'Line Item 1' - 'Line Item 1'[LOOKUP: Custom Day.'Current Day-90']


The Above formula gives average but not moving average. Any suggestions, please?





Best Answer

  • rob_marshall
    Answer ✓

    @aishabhy05 ,


    This is how I would handle it.  Create a mapping module from Fake Time to Real Time and use the MovingSum() function on Real Time.  Then do a lookup to Real Time from the mapping module to get your data for reporting.




  • @aishabhy05 


    Sorry i forgot to respond to your follow up on the other post. 


    Here is how I would probably do this. 


    You are on the right track with the Cumulate. But we just want to keep a running cumulate going:




    From there, we can then calculate what our 10 week ago week would be with a formula like the following: FINDITEM(Fake time, TEXT(VALUE(NAME(ITEM(Fake time))) - 10)) It would be best to stage this out to not calculate it all on one line.




    From there, we can see what the current value of the cumulative line is, subtract what it was 10 periods ago, and divide this by 10. : (Cumulate Line - Cumulate Line[LOOKUP: '10 week Ago']) / 10



    I am sure there are other ways to go about this as well, but this should work.


    Let me know if there are other questions!




  • Thanks @jasonblinn  for your swift response. The average is running, but I have an issue from next week/day the current week Average should be Considered. The above formula works well for moving average. But for forecasting the sales data Clients requesting the last 90 days average and for forecasting days it should include the Current Day Average. Any workaround for this, please?




  • Thanks @rob_marshall .  This is in line with my thought as well. 


    I tried another method, not sure the following method is efficient


    Steps: Input module Past Data in Custom Time





    Step 2: Calculating Avg for Current Period




    Step 3: Rolling the calculated forecast to future periods.  Using Subset every week it moves when the data will be uploaded. Calculated the Avg Sales Twice, not sure whether this method is efficient. 




    I suspect calculating Avg twice may affect the performance. 

    Welcoming Suggestions. 






  • @aishabhy05 ,


    Honestly, I think using a real time module and using MovingSum() will be easier and more performant than the hoops you are having to jump through.



  • Hi Rob @rob_marshall ,


    I just posted a new question inspired by this post.  I am working with custom timescale (days) but I needed to use the system days to do some calculation. I struggled to map the result from system time module back to custom time module. 


    I was wondering if you could kindly elaborate the " Then do a lookup to Real Time from the mapping module to get your data for reporting." ? 


    Many thanks,



  • @LilyLiuAnaplan 


    I guess it depends on the format of your "custom" days.

  • Thank you so much Rob. @rob_marshall 


    Below is a copy of my question. 


    I have below module using Days as time dimension. I also have a line called fake days where I mapped the system days to a fake days list.  



    Then I would like to do a LOOKUP to pull the data from the above module to a module with the fake day list as dimension.  Time is not a dimension.





    Thanks for your help.





  • I will reply in the other thread