Forum Discussion

Masikonde's avatar
Masikonde
Frequent Visitor
6 years ago
Solved

Trailing Average

Hi all,   I have been trying to move all reports calculations from excel spreadsheets, and completely using Power BI. I'm having an issue calculating trailing 12 months trailing average in Power BI...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Masikonde ,

    I'd like to suggest you do unpivot columns on your table, then you can write a measure formula to loop all fields for rolling calculations based on its attribute.

    Unpivot columns (Power Query)

    Measure =
    VAR currDate =
        MAX ( Table[Date] )
    RETURN
        CALCULATE (
            AVERAGE ( Table[Value] ),
            FILTER ( ALLSELECTED ( Table ), [Date] <= currDate ),
            VALUES ( Table[Attribute] )
        )
    

    Regards,

    Xiaoxin Sheng