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
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
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.