Forum Discussion

AdamMG's avatar
AdamMG
Helper I
2 years ago
Solved

Measure - moving/rolling average

Hi Everyone. I am trying to create a measure (must be measure) - moving/rolling average (2 or 5 results) for DupResult column. My Table looks like rowid DupResult OrigResult 213034 8....
  • Jihwan_Kim's avatar
    2 years ago

    Hi,

    Please check the below picture and the attached pbix file.

     

     

    INDEX function (DAX) - DAX | Microsoft Learn

     

    WINDOW function (DAX) - DAX | Microsoft Learn

     

    2 rows moving avg DupResult: =
    VAR _previousrow =
        MAXX (
            OFFSET (
                -1,
                ALL ( data ),
                ORDERBY ( data[rowid], ASC ),
                ,
                ,
                MATCHBY ( data[rowid] )
            ),
            data[rowid]
        )
    VAR _t =
        WINDOW (
            -1,
            REL,
            0,
            REL,
            ALL ( data ),
            ORDERBY ( data[rowid], ASC ),
            ,
            ,
            MATCHBY ( data[rowid] )
        )
    RETURN
        IF (
            _previousrow <> BLANK ()
                && HASONEVALUE ( data[rowid] ),
            AVERAGEX ( _t, data[DupResult] )
        )