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
homboy27
Helper II
Helper II

Last 2 weeks average/ employee

Please see below data. I am calculating total sales divided by total hours in column I by employee. But I would like to calculate last 2 weeks average by employee in column J. 

 

So for example in Column J, I am calculating last 2 weeks average per employee. How would I do that in Power BI? How would I create column J? So for example for Mike it is calculating (10+10)/(25+25) and for Sonia it is calculating (10+15)/(25+25)

 

homboy27_1-1742408693656.png

 

 

 

 

4 REPLIES 4
parry2k
Super User
Super User

@homboy27 change the DAX measure to this, and replace the value of __lastHowManyWeeks with 8 or whatever value you want, you can also make it dynamic:

 

Last x Weeks Average = 
VAR __LastHowManyWeeks = 2 --change this to number of weeks you are looking for.
VAR __WeekEnding = MAX ( 'Table'[Week Ending] )
VAR __WeekStart = __WeekEnding - ( ( __LastHowManyWeeks - 1 ) * 7 )
RETURN
AVERAGEX (
    FILTER ( 
        ALLSELECTED ( 'Table'[Week Ending] ),
        'Table'[Week Ending] >= __WeekStart && 'Table'[Week Ending] <= __WeekEnding
    ),
    [% Hours]
)


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.

Thank you, what do you mean by make it more dynamic?

Syndicate_Admin
Administrator
Administrator

@Syndicate_Admin see attached, tweak the solution as you see fit.

thank you, what is the formuala if I wanted to do average of last 8 weeks?

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