Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Subtract previous average from current average

Hi Dax community,   I would like to calculate the difference in average satisfaction between the current and previous period but I could not figure out a DAX.  I tried indexing and using the earlie...
  • v-cazheng-msft's avatar
    4 years ago

    Hi Anonymous,

     

    You may try this solution.

    1 Create a Calculated column

    Date =
    VAR Month_ =
        SWITCH (
            LEFT ( 'Table'[Survey Period], 3 ),
            "Jan", 1,
            "Feb", 2,
            "Mar", 3,
            "Apr", 4,
            "May", 5,
            "Jun", 6,
            "Jul", 7,
            "Aug", 8,
            "Sep", 9,
            "Oct", 10,
            "Nov", 11,
            "Dec", 12
        )
    VAR Year_ =
        2000 + RIGHT ( 'Table'[Survey Period], 2 )
    RETURN
        DATE ( Year_, Month_, 1 )

     

    2 Create the following Measures

    Current = CALCULATE(AVERAGE('Table'[Satisfaction]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])))

     

    Previous = CALCULATE([Current],FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])))

     

    Difference = IF(ISBLANK([Previous]),BLANK(),[Current]-[Previous])

     

    Then, the result looks like this.

     

    Also, attach the pbix file as reference. Hope it helps.

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

     

    Best Regards,

    Community Support Team _ Caiyun