Forum Discussion

wkeicher's avatar
wkeicher
Icon for Helper III rankHelper III
7 years ago
Solved

Include Employee start and end date in Utilization %

I am calcualting Employee project utilization from Time sheet data and calendars that identifyy a work day and non work day, however, i need to now adjust utilization for terminated employees as thay...
  • Anonymous's avatar
    Anonymous
    7 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

  • Anonymous's avatar
    Anonymous
    7 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