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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jacob1832
Frequent Visitor

Rolling 4 week average by state

I am trying to create a rolling 4 week average of the Actuals column and grouped on the State. 

So startring at the bottom, the 4 week average for TX in the final row would be, (1+ 0 (no sales in week of may22) + 1+3) / 4 (number of weeks). 

Jacob1832_0-1654644539399.png

So in think for a given week and state observation, i would need to sum all 'Actual' values in a 4 week period including the current obersation, grouped by the State, then divide by the number of weeks.

 

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

Hi @Jacob1832 ,

 

Please try this measure.

Rolling 4 week average of the Actuals = 
VAR _given_week =
    MAX ( 'Table'[Week] )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Actuals] ),
        'Table'[Week] >= _given_week - 21
            && 'Table'[Week] <= _given_week
    ) 
VAR _average =
    DIVIDE ( _sum , 4 ) + 0
RETURN
    _average

vcgaomsft_0-1655186090904.png

Attached PBIX file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Jacob1832 ,

 

Please try this measure.

Rolling 4 week average of the Actuals = 
VAR _given_week =
    MAX ( 'Table'[Week] )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Actuals] ),
        'Table'[Week] >= _given_week - 21
            && 'Table'[Week] <= _given_week
    ) 
VAR _average =
    DIVIDE ( _sum , 4 ) + 0
RETURN
    _average

vcgaomsft_0-1655186090904.png

Attached PBIX file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

vapid128
Solution Specialist
Solution Specialist

 

2022-06-07 174410.png

屏幕截图 2022-06-07 174605.png

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.