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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Calculate weekly moving average

Hi,

 

My data looks like the below:

 

Project Count       |       YearWeek

15                                 201803

20                                 201802

30                                 201801

10                                 201753

40                                 201752

 

I have created the below measure to calculate the 12 week moving average from current date going back in time. However, I don't know how to move back in time across years, for example, for the year weeks 201803 or 201802 or 201801 I will need to include the project count for 201753, 201752 etc as the range is 12 weeks. I don't know how to add the logic: IF extracting a project count from the "01" of a year, the next project count should be added from CurrentYear -1 and the MAX week within that year....

 

12wk Average = 
CALCULATE(SUM(Table1[CountProj]),
    FILTER(
        ALL(Table1[YearWeek] ),
        (
            (
                Table1[YearWeek]
                    >= MAX (Table1[YearWeek] ) - 11
            )
                && (
                    Table1[YearWeek]
                        <= MAX ( Table1[YearWeek] ) - 0
                )
        )
    ))/12

 

 

Any help appreciated.

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

I'd use TOPN, e.g. something like this

12wk Average =
VAR LastWeek =
    MAX ( Table1[YearWeek] )
VAR Last12Weeks =
    TOPN (
        12,
        FILTER ( ALL ( Table1[YearWeek] ), Table1[YearWeek] <= LastWeek ),
        [YearWeek], DESC
    )
RETURN
    DIVIDE ( CALCULATE ( SUM ( Table1[CountProj] ), Last12Weeks ), 12 )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

1 REPLY 1
Stachu
Community Champion
Community Champion

I'd use TOPN, e.g. something like this

12wk Average =
VAR LastWeek =
    MAX ( Table1[YearWeek] )
VAR Last12Weeks =
    TOPN (
        12,
        FILTER ( ALL ( Table1[YearWeek] ), Table1[YearWeek] <= LastWeek ),
        [YearWeek], DESC
    )
RETURN
    DIVIDE ( CALCULATE ( SUM ( Table1[CountProj] ), Last12Weeks ), 12 )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors