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
DRossi
Helper III
Helper III

Find earliest arrival time for a day then compare against shift start time

Morning all,

 

I have a data set that has multiple timestamps in columns Table1[WORK_CONDUCTED.2] that show arrival times for an engineer. There are multiple timestamps for each engineer throughout the day as they visit multiple customers. So, I'm just interested in their first Arrival time.

 

I also have a dataset loaded in that shows the Engineer Start time Table2[ShiftStart] for that day. 

 

So for for each day worked, I want to find total lost time through something like this: (Earliest or Minimum) Table1[WORK_CONDUCTED.2] - Table2[ShiftStart].

So in theory engineer arrived at 08:46:00 but their shift start time was 08:30:00 so we can then see that there was 16 minutes lost time for that day. If the engineers arrival time was earlier than their shift start time, this is fine and I don't want to capture this as it has resulted in no lost time.

 

 

I would also want it to sum up for a weeks/month or defined periods total lost time.

 

Quite complex I think, but I can't seem to get anything that works.

 

 

 

 

1 ACCEPTED SOLUTION
EricHulshof
Solution Sage
Solution Sage

You can do this with datediff:

Lost = DATEDIFF(MAX(Table1[Workconducted]);MAX(Table2[ShiftStart]);MINUTE)

 


Quality over Quantity


Did I answer your question? Mark my post as a solution!


View solution in original post

7 REPLIES 7
EricHulshof
Solution Sage
Solution Sage

You can do this with datediff:

Lost = DATEDIFF(MAX(Table1[Workconducted]);MAX(Table2[ShiftStart]);MINUTE)

 


Quality over Quantity


Did I answer your question? Mark my post as a solution!


@EricHulshof  Actually, that measure finds the earliest in the set of dates and latest shift in the defined period from the date slicer. So if selected one day the data is correct, but as soon as I select a wide range date period, it only finds the earliest ON Site time for that period and does the calculation for that day.

 

I need it to total each day and give a sum of lost time for each day.

datediff.PNG

I assumed both starttime and arrival time were DateTime values. Can you give me some sample data to help you better? 🙂


Quality over Quantity


Did I answer your question? Mark my post as a solution!


@EricHulshof  Please see tables

Engineer nameDateOn Site time

Daniel01/01/202008:20:00
Daniel01/01/202009:10:00
Daniel01/01/202013:10:00
Fred01/01/202008:16:00
Fred01/01/202010:20:00
Fred01/01/202012:10:00
Daniel 02/01/202010:00:00
Daniel02/01/202011:00:00
Daniel02/01/202012:15:00
Fred02/01/202009:13:00
Fred02/01/202009:45:00

 

Engineer nameDateShiftStart

Daniel01/01/202008:00:00
Fred01/01/202008:00:00
Daniel02/01/202008:00:00
Fred02/01/202008:00:00

For example, Lost time for Daniel on 1st Jan was 20 minutes and for Fred, 16 mins.

 

The formula needs to look for the day, from that day, what was the earliest OnSite time and compare that against the engineers ShiftStart time, thus giving the Lost time. But I also need that to sum up too as for example, if I have a slicer that selects a month period, I want it to tell me lost time for that whole period.

 

Thanks 🙂

@DRossi 
Heya,

 

I created a relation on a Many to Many setting between the dates and used this measure.

 

measure = CALCULATE(Datediff(MIN(Workconducted[On Site time]);MAX(ShiftStart[ShiftStart]);MINUTE);FILTER(Workconducted;Workconducted[Date] = Workconducted[Date]))

 Result:

Knipsel.PNG


Quality over Quantity


Did I answer your question? Mark my post as a solution!


Thanks, @EricHulshof . I aprreciate your efforts. This is returning the right way on the table as start times are 8AM, great 🙂 however, it still isn't summing up a total for the defined period. See below:

 

 
 

sumup.PNG

Is there something I can add to DAX to  sum up?

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.