Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
L_Oram
Regular Visitor

Rolling 13 Period Average of Hours

Afternoon All 🙂

 

I'd like to create a measure that would give me the rolling average hours from the past 13 months. What is the best way to go about it? sample data below

 

FYPeriodTotal Hours
2022051333119.5
2022061337301.75
2022071362952.22
2022081484211.8
2022091483151.11
2022101300528.75
2022111393122
2022121499369.5
2022131427705.5
2023011436508.5
2023021308720.5
2023031307649.5
2023041310249.5
2023051350095.5
2023061411667.5
2023071384331.5
2023081398125.5
2023091669522.5
2023101353769.5
2023111400674
2023121361626
2023131320563.5
2024011227380
2024021277859
2024031358457
2024041365336
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @L_Oram ,

You can generate the desired output using a DAX measure like the one below:

Moving Average 13 Months = 
VAR CurrentPeriod = MAX('Table'[FYPeriod])
VAR Last13Periods =
    TOPN(
        13, 
        FILTER(
            ALL('Table'), 
            'Table'[FYPeriod] <= CurrentPeriod
        ),
        'Table'[FYPeriod], 
        DESC
    )
VAR Result = 
    CALCULATE(
        AVERAGEX(
            Last13Periods,
            'Table'[Total Hours]
        )
    )
RETURN
    Result

 This will produce the output like below:

DataNinja777_0-1724428682425.png

Since your calendar has 13 periods and is non-standard, I didn't create a separate calendar table, although using a separate calendar table in the data model is considered best practice.

I have attached an example PBIX file.

View solution in original post

3 REPLIES 3
DataNinja777
Super User
Super User

Hi @L_Oram ,

You can generate the desired output using a DAX measure like the one below:

Moving Average 13 Months = 
VAR CurrentPeriod = MAX('Table'[FYPeriod])
VAR Last13Periods =
    TOPN(
        13, 
        FILTER(
            ALL('Table'), 
            'Table'[FYPeriod] <= CurrentPeriod
        ),
        'Table'[FYPeriod], 
        DESC
    )
VAR Result = 
    CALCULATE(
        AVERAGEX(
            Last13Periods,
            'Table'[Total Hours]
        )
    )
RETURN
    Result

 This will produce the output like below:

DataNinja777_0-1724428682425.png

Since your calendar has 13 periods and is non-standard, I didn't create a separate calendar table, although using a separate calendar table in the data model is considered best practice.

I have attached an example PBIX file.

ThxAlot
Super User
Super User

Running Avg WINDOW = 
AVERAGEX(
    WINDOW( -12, REL, 0, REL, ORDERBY( DATA[FYPeriod] ) ),
    CALCULATE( SUM( DATA[Total Hours] ) )
)
Running Avg TOPN = 
VAR __p =
    MAX( DATA[FYPeriod] )
RETURN
    AVERAGEX(
        TOPN(
            13,
            CALCULATETABLE( DATA, DATA[FYPeriod] <= __p ),
            DATA[FYPeriod], DESC
        ),
        DATA[Total Hours]
    )

ThxAlot_1-1724428579699.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



dharmendars007
Super User
Super User

Hello @L_Oram , 

Thanks for your question..

Please find the DAX to be written to get the rolling Average 13 months without dates..You have to create the Index column starting 1 in Power Query to achive this

dharmendars007_1-1724426610076.png

 

Rolling Average13 =


VAR _MaxIndex = MAX('Table'[Index])

VAR _MinIndex = _MaxIndex - 13

VAR _Filter13Months = FILTER(ALL('Table'),
                                'Table'[Index] <= _MaxIndex &&
                                'Table'[Index] > _MinIndex)

VAR _RollingAvg = AVERAGEX(_Filter13Months, 'Table'[Total Hours])

Return
_RollingAvg


dharmendars007_0-1724426013234.png

If you find this helpful , please mark it as solution and give kudos
Thank You
Dharmendar S
LinkedIN 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.