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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
bharatsrini123
Regular Visitor

Calculate last 5 weeks rolling average.

Hi I am trying to calculate last 5 weeks rolling average of sum of a set of values and divide it by the last 5 weeks rolling average of count of the same set of values. I did it using a normal calculation function but it does not seem to work. I am trying to implement using averagex function but keep getting issues. Any help will be appreciated.

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @bharatsrini123 ,

 

Please try the measure.

 

last 5 weeks rolling average =
VAR tab =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Week]
            > MAX ( 'Calendar'[Week] ) - 5
            && 'Calendar'[Week] <= MAX ( 'Calendar'[Week] )
    )
VAR Ave_Sum =
    AVERAGEX (
        SUMMARIZE ( tab, 'Calendar'[Week] ),
        CALCULATE ( SUM ( 'Table'[Values] ) )
    )
VAR Ave_Count =
    AVERAGEX (
        SUMMARIZE ( tab, 'Calendar'[Week] ),
        CALCULATE ( COUNT ( 'Table'[Values] ) )
    )
RETURN
    DIVIDE ( Ave_Sum, Ave_Count )

vkkfmsft_0-1653545667298.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-kkf-msft
Community Support
Community Support

Hi @bharatsrini123 ,

 

Please try the measure.

 

last 5 weeks rolling average =
VAR tab =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Week]
            > MAX ( 'Calendar'[Week] ) - 5
            && 'Calendar'[Week] <= MAX ( 'Calendar'[Week] )
    )
VAR Ave_Sum =
    AVERAGEX (
        SUMMARIZE ( tab, 'Calendar'[Week] ),
        CALCULATE ( SUM ( 'Table'[Values] ) )
    )
VAR Ave_Count =
    AVERAGEX (
        SUMMARIZE ( tab, 'Calendar'[Week] ),
        CALCULATE ( COUNT ( 'Table'[Values] ) )
    )
RETURN
    DIVIDE ( Ave_Sum, Ave_Count )

vkkfmsft_0-1653545667298.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors