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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.