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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors