Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
3 years ago
Solved

QUERY - DAX code for Exponential Moving Average calculation - EMA

Hello PBI community.

Any experts to guide me on how to break down the DAX code to calculate the Exponential Moving Average for 30 days?

Thanks a lot

RJRO

  • Anonymous's avatar
    Anonymous
    3 years ago

    HI RAFAJRO,

    You can create a variable to store the current axis date and use it as conditions to filter on your fact table records and get rolling average based on specific date ranges.

    formula =
    VAR currdate =
        MAX ( Calendar[Date] )
    RETURN
        CALCULATE (
            AVERAGE ( Table[Amount] ),
            FILTER ( ALLSELECTED ( Table ), [Date] >= currdate - 30 && [Date] <= currDate )
        )

    Regards,

    Xiaoxin Sheng

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI RAFAJRO,

    You can create a variable to store the current axis date and use it as conditions to filter on your fact table records and get rolling average based on specific date ranges.

    formula =
    VAR currdate =
        MAX ( Calendar[Date] )
    RETURN
        CALCULATE (
            AVERAGE ( Table[Amount] ),
            FILTER ( ALLSELECTED ( Table ), [Date] >= currdate - 30 && [Date] <= currDate )
        )

    Regards,

    Xiaoxin Sheng