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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MNLegoman
Frequent Visitor

Moving average with Measured Index

Hello Community, 

   I'm brand new to Power BI, so please bear with me. I'm converting my excel dashboard into a power bi dashboard. One of my charts is a 4-week moving average. I'm able to do this in excel with a pivot table and a separate column that calculates the average of the previous 4 weeks (charted as the red line).

 

MNLegoman_0-1613335232042.png

 

Ok, so now I'm converting to Power bi. I've got my "matrix" view of the table and added a "row number" column (created as a measure because it is relative to the filters), but I cannot for the life of me figure out how to calculate the 4 week moving average. All of the examples I run into have the "index" as a column not a measure OR they are averaging a column and not a measure. In my case, Row_Number AND Avg_Task_Dur are measures impacted by the filters.

 

Avg_Task_Dur = AVERAGE(CFTaskDetails[Task Dur (total)])
 
Row_Number =
CALCULATE (
DISTINCTCOUNT(CFTaskDetails[Notif Closd YR-WK]),
FILTER ( ALLSELECTED (CFTaskDetails[Notif Closd YR-WK] ), CFTaskDetails[Notif Closd YR-WK] <= MAX( CFTaskDetails[Notif Closd YR-WK]) ))
 

 

MNLegoman_1-1613335462673.png

 

Note: the 4 week moving average is an average of the averages for the last 4 weeks.

 

I would greatly appreciate any help... Thanks!

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@MNLegoman here is the measure for you:

 

Avg_Task_Dur = 
VAR __currentRowNumber = [Row_Number]
VAR __startRow = [Row_Number]  - 3
VAR __Result = 
    AVERAGEX ( 
        SUMMARIZE ( 
            ALLSELECTED ( CFTaskDetails[Notif Closd YR-WK] ), 
            CFTaskDetails[Notif Closd YR-WK], 
            "@Row", [Row_Number] 
        ),
        IF ( [@Row] >= __startRow && [@Row] <= __currentRowNumber,
            CALCULATE ( 
                SUM ( CFTaskDetails[Task Dur (total)] )
            )
        )
    )
RETURN __Result

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@MNLegoman glad it worked out. Cheers!!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@MNLegoman here is the measure for you:

 

Avg_Task_Dur = 
VAR __currentRowNumber = [Row_Number]
VAR __startRow = [Row_Number]  - 3
VAR __Result = 
    AVERAGEX ( 
        SUMMARIZE ( 
            ALLSELECTED ( CFTaskDetails[Notif Closd YR-WK] ), 
            CFTaskDetails[Notif Closd YR-WK], 
            "@Row", [Row_Number] 
        ),
        IF ( [@Row] >= __startRow && [@Row] <= __currentRowNumber,
            CALCULATE ( 
                SUM ( CFTaskDetails[Task Dur (total)] )
            )
        )
    )
RETURN __Result

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

OMG, you are a lifesaver! With one small tweak, (change SUM to AVERAGE) this is exactly what I needed. 

Thank you, thank you!

 

Change made:

average(CFTaskDetails[Task Dur (total)])
parry2k
Super User
Super User

@MNLegoman It will be easier if you share pbix file using one drive/google drive with the expected output. Remove any sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hope this works

 

(Link Removed)

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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