powerbidaxpowerbi-desktop

DAX measure is not cooperating


I am trying to get a Total Hours Worked Column inside this visual that will show as "0" if the start time and end time are the same.

This indicates the driver forgot to log out of the application, there should be no 24 hr entries.

Here is my measures being utilized.

Hours Worked = 

VAR earlieststart = CALCULATE(MIN('HOS Logs 1 0'[StartTime]),'HOS Logs 1 0'[Status]<> "offDuty")

VAR latestworktime = CALCULATE(MAX('HOS Logs 1 0'[EndTime]),'HOS Logs 1 0'[Status]<>"offDuty")

VAR timeworked = DATEDIFF(earlieststart,latestworktime,HOUR)

RETURN

IF(MIN('HOS Logs 1 0'[StartTime]) = MAX('HOS Logs 1 0'[EndTime]),0,timeworked)
Total Hours Worked = SUMX('HOS Logs 1 0',[Hours Worked])  
Total Hours Worked2 = SUMX('HOS Daily Logs 1 0',IF('HOS Daily Logs 1 0'[StartTime] = 'HOS Daily Logs 1 0'[EndTime], 0, [Total Hours Worked]))

total hours 2 is not working as it should. For entry 4, start and end times do not match, but the column is still returning 0.enter image description here


Solution

  • I would gues that your start and end time could differ.

    In power bi time has granularity of a second.

    So if [Start time] is older than [End time] by one second, that will lead to the false scenario.

    I also would suggest you to use calculated column instead of measure as a general best practice approach.

    Best Regards,