Forum Discussion
Include Employee start and end date in Utilization %
- Anonymous7 years ago
Utilization = -- Each user must have a unique name. -- If this is not the case, you should -- use a field that uniquely identifies -- a user. Such a field should be marked -- in Power BI as a row identifier. var __visibleUsers = SUMMARIZE( Users, Users[Name], Users[StartDate], Users[TerminationDate] ) var __numberOfWorkingHoursADay = 7.5 var __utilization = AVERAGEX( __visibleUsers, var __userStartDate = Users[StartDate] var __userEndDate = if( Users[TerminationDate] = BLANK(), date(2099, 1, 1), Users[TerminationDate] ) var __totalPossibleWorkingDays = COUNTROWS ( FILTER ( 'Working Dates', 'Working Dates'[IsWorkday] = "Yes", KEEPFILTERS( 'Working Dates'[Date] >= __userStartDate ), KEEPFILTERS( 'Working Dates'[Date] <= __userEndDate ), ) ) var __totalPossibleWorkingHours = __totalPossibleWorkingDays * __numberOfWorkingHoursADay var __totalMandatoryWorkedHours = CALCULATE ( SUM ( 'ActivityUpdates'[Hours] ), 'Working Dates'[IsWorkday] = "Yes" ) var __totalOvertimeWorkedHours = CALCULATE ( SUM ( 'ActivityUpdates'[Hours] ), 'Working Dates'[IsWorkday] = "No" ) var __totalWorkedHours = __totalMandatoryWorkedHour + __totalOvertimeWorkedHours var __totalPossibleWorkingHours = __totalPossibleWorkingHours + __totalOvertimeWorkedHours return divide( __totalWorkedHours, __totalPossibleWorkingHours ) ) RETURN __utilization
Best
Darek
- Anonymous7 years ago
OK, but what do you expect to see in the third column for each row? Would you please put the figures in there? It would be good if you could share a sample file and tell me what the measure should return for the visual(s) you've got in there. It's really hard to see where the formula breaks if there's no expectation set.
I need to see the data model, mate. If you have any cross-filtering, it might screw up the calculations. I just wonder why 'Working Dates' has a column DateAsInteger. You should not compare an int to a date (which __userStartDate and __userEndDate are). This will not return an error because of an automatic conversion since Date is stored as float and an int can be turned into a float as well.
Thanks.
Best
Darek
Now it's clear. I understand. Before, I did not understand what you wanted to do. If you had added the cases before, I'd have written the correct formula then and there. Give me some time and I'll update the code to take this into account. I'm at work now...
Best
Darek
Awesome - Thanks...!