Forum Discussion

Philip-K's avatar
Philip-K
Frequent Visitor
9 years ago
Solved

Calculating moving average

Hi,   I'm trying to calculate the moving average over the past year for every month. I have formed a table with 4 columns: Jaarmaand = year+"-"+month Aantal oorzaken = count of a certain event (t...
  • jmdh's avatar
    jmdh
    9 years ago

    Hi Philip,

     

    Glad it works for you.
    regarding your question 2, just remove 31 days to sdate : this is sdate that contains the start date of the first result.

     

    regarding 1, there is a function EDATE that should do it:

    Amount MAVG2b =
    var sdate=Min(Amounts[Date])+365-31 // This is the month when to start displaying results (used below in IF)
    var d = 'Amounts'[Date]  // the current date
    var d365 =EDATE(d,-12)  // this calculates a date 12 months before (i assume it works with leap years)
    var r=
    IF(d>=sdate,
     SUMX(
      FILTER('Amounts',  Amounts[Date] <= d  && Amounts[Date] > d365),
      [Amount]
      )
     /12  
    )
    RETURN
    r