Forum Discussion

Applicable88's avatar
Applicable88
Icon for Impactful Individual rankImpactful Individual
5 years ago
Solved

Convert a table without date into a 6 Month (6 steps Moving Average

Hello, my table consist of three columns. One is the YearMonthKey, Date and another percentage where I want to get my moving average from:   I marked my calendar table as "date table" but th...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Applicable88 

    I know you want to calculate the 6 month rolling average of sum of percentages. And your Date column is not in date type.

    Try my way to achieve your goal. I build a sample data model like yours to have a test.

    Sample: 

    Add a Rank column by dax, and we don't need to use date type column.

    Rank = RANKX('Table','Table'[YearMonthKey],,ASC,Dense)

    Measure:

     

    Rolling 6 Avg = 
    VAR _EndRank = MAX('Table'[Rank])
    VAR _StartRank = _EndRank-6
    VAR _Rolling6Sum = SUMX(FILTER(ALL('Table'),'Table'[Rank]<=_EndRank&&'Table'[Rank]>_StartRank),'Table'[Percentage])
    VAR _Avg = DIVIDE(_Rolling6Sum,6)
    Return
    _Avg

     

    Result is as below. Rolling 6 Avg in 202105 = 55,60%. 

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.