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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
homboy27
Helper III
Helper III

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

 

 

 

 

8 REPLIES 8
v-sathmakuri
Community Support
Community Support

Hi @homboy27 ,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you!!

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?

Hi @homboy27 ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

please find the below measure to calculate for 8 weeks. Also attached the pbix file for reference.

 

Last 8 Weeks Average =
VAR __WeekEnding = MAX ( 'Table'[Week Ending] )
VAR __WeekStart = __WeekEnding - 56
RETURN
AVERAGEX (
    FILTER (
        ALLSELECTED ( 'Table'[Week Ending] ),
        'Table'[Week Ending] >= __WeekStart && 'Table'[Week Ending] <= __WeekEnding
    ),
    [% Hours]
)
 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

Hi @homboy27 ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

 

Thank you!!

Hi @homboy27 ,

 

I hope the information provided is helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can

find a solution faster.

 

Thank you!!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.