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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
simonfalun
Frequent Visitor

Calculating an average by person

I've been searching over and over, but I can't find the solution - so I'm afraid that there isn't any solution to this.

I have a table ("Time reports") with all reporting for our employes, grouped by Person and Date. The table looks like this example:

 

DatePersonBilled hours
2017-04-12Joe5
2017-04-13Joe8
2017-04-13Chris8,5
2017-04-13Dave6
2017-04-13Martin5
2017-04-14Chris7
2017-04-14Dave4
2017-04-14Martin5
2017-04-15Joe8
2017-04-15Chris8
2017-04-15Dave6
2017-04-16Martin9
2017-04-17Joe8
2017-04-17Chris8
2017-04-17Dave6
2017-04-17Martin5

 

I want to calculate the average of hours/day for each person individually. The average should be over the latest 10 reported days, per person.
Every person doesn't have reports for every day, so the latest 10 reported days won't be the same for every person.

 

In any other language I would have accompliced this by looping through the persons and count 10 days from a descending list - but how do I do in DAX or Power Query!?


One thought was to calculate this in the SQL-server - BUT, the table is merged from multiple data sources (Both SQL and Excel since we have multiple systems for time reporting) and each person can occur in both data sources.

1 ACCEPTED SOLUTION
mattbrice
Solution Sage
Solution Sage

Assuming you only have the 'Person' on rows, then while i have not tested it this should work:

 

 

 

Avg per Person last 10 reported days = 
CALCULATE ( AVERAGE ( 'Time Reports'[Billed Hours] ); TOPN ( 10, VALUES ( 'Time Reports'[Date] ); LASTDATE ( 'Time Reports'[Date] ) ) )

 

View solution in original post

3 REPLIES 3
mattbrice
Solution Sage
Solution Sage

Assuming you only have the 'Person' on rows, then while i have not tested it this should work:

 

 

 

Avg per Person last 10 reported days = 
CALCULATE ( AVERAGE ( 'Time Reports'[Billed Hours] ); TOPN ( 10, VALUES ( 'Time Reports'[Date] ); LASTDATE ( 'Time Reports'[Date] ) ) )

 

AWESOME! Thank you - you just turned my **bleep**ty day into a really great day!! Smiley Very Happy

I created a new table with only the persons and added a calculaded column with your code - worked like a charm!

 

Next step for me is to analyze the code so I can understand how it works Smiley Happy

 

Have a great day everyone!

Hi @simonfalun,

 

I just verified that the formula provided by @mattbrice above should work in your scenario. Smiley Happy

 

@mattbrice, nice solution! Kudos +1. Smiley Wink

 

Regards

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors