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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AP-BOB
Frequent Visitor

"Count If" at an aggregated level

Hello,

 

I am trying create a dashboard that identifies how many employees are entering below 40 hours per week. I need to then display by percentage how many employees are on or over 40 hours, and how many are below.

 

I am new to DAX and really struggling with the syntax especially when the data is at the day/task level.

 

Sample data below:

 

IDTimekeeper NameTaskDateHours worked
1John SmithMeetings1/7/20193
1John SmithDevelopment1/7/20194
1John SmithMeetings1/8/20195
1John SmithDevelopment1/8/20193
1John SmithMeetings1/9/20192
1John SmithDevelopment1/9/20198
1John SmithMeetings1/10/20198
1John SmithMeetings1/11/20197
1John SmithMeetings1/14/20196
1John SmithMeetings1/15/20198
1John SmithMeetings1/16/20198
1John SmithMeetings1/17/20198
1John SmithMeetings1/18/20199
2Jane DoeAnalysis1/7/20193
2Jane DoeMeetings1/7/20197
2Jane DoeAnalysis1/8/20192
2Jane DoeMeetings1/8/20194
2Jane DoeAnalysis1/9/20194
2Jane DoeMeetings1/9/20194
2Jane DoePTO1/10/20198
2Jane DoeAnalysis1/11/20196
2Jane DoeAnalysis1/14/201911
2Jane DoeAnalysis1/15/20198
2Jane DoeAnalysis1/16/20197
2Jane DoeAnalysis1/17/20198
2Jane DoeAnalysis1/18/20198

 

Thank you.

1 ACCEPTED SOLUTION
PANDAmonium
Resolver III
Resolver III

First you have to group by week. So in Power Query:

- Create a week column with a function like "= Table.AddColumn(#"Changed Type", "Custom", each Date.WeekOfYear([Date]))"

- Group By Week and Time Keeper Name with an aggregation for Sum of Hours Worked

 

And then it's just a matter of creating a measure to calculate percentages so count of hours gte 40 divided by count of all so:

Percentage = CALCULATE(COUNT('HRS'[Timekeeper Name]),HRS[Count]>=40) / COUNT(HRS[Timekeeper Name])
 
Example Percentage Over 40 Hours.PNG

View solution in original post

6 REPLIES 6
PANDAmonium
Resolver III
Resolver III

First you have to group by week. So in Power Query:

- Create a week column with a function like "= Table.AddColumn(#"Changed Type", "Custom", each Date.WeekOfYear([Date]))"

- Group By Week and Time Keeper Name with an aggregation for Sum of Hours Worked

 

And then it's just a matter of creating a measure to calculate percentages so count of hours gte 40 divided by count of all so:

Percentage = CALCULATE(COUNT('HRS'[Timekeeper Name]),HRS[Count]>=40) / COUNT(HRS[Timekeeper Name])
 
Example Percentage Over 40 Hours.PNG

Thanks for the info. When you say "- Group By Week and Time Keeper Name with an aggregation for Sum of Hours Worked", do I do that by creating a new table or somehow at the measure level?

You're transforming the hours worked table, so in Power Query > Transform > Group By > Advanced

Just a quick follow-up question. I am assuming this method will replace my current table? If so, I still need the granular details for other visualization. Do I just create another table?

Not necessarily. Either duplicate or reference the original table first.

Worked wonderfully. Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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