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
manyerukebenn
Regular Visitor

Date Difference for two rows

I am having problems calculating date difference for the below scenario. I want to calculate the total time spent on a particular job by a mechanic. When the mechanic start and pause we should calculate the difference between the two times, when he resumes and completes the task we should also calculate the difference between the 2nd start time and the completion time, finally we sum the 2 date differences. Time taken = (Pausedtime-Starttime)+( CompleteTime- Starttime)

On the below scenario the expected result is 10 munites

 

Fleet No.DocEntryTaskCodeTask DescriptionStatus Mechanic Activity TimeJob TitleExpected Result
T0013SFREN24ENGINE OIL LEAK MINORStartedMechanic 114/03/2018 17:58Diesel Mechanic 
T0013SFREN24ENGINE OIL LEAK MINORPausedMechanic 114/03/2018 18:03Diesel Mechanic5 min
T0013SFREN24ENGINE OIL LEAK MINORStartedMechanic 115/03/2018 10:40Diesel Mechanic 
T0013SFREN24ENGINE OIL LEAK MINORStoppedMechanic 115/03/2018 10:45Diesel Mechanic5min
        10 min
1 REPLY 1
Chthonian
Helper III
Helper III

Hi @manyerukebenn 

I am a bit of an amateur and there would be a much more sophisticated way to achieve this  but this solution worked for me 🙂

 

Job Duration = 
    VAR JobStart = CALCULATE(MIN(Table1[Activity Time]), Table1[Status ] = "Started")
    VAR BreakStart = CALCULATE(MIN(Table1[Activity Time]), Table1[Status ] = "Paused")
    VAR BreakEnd = CALCULATE(MAX(Table1[Activity Time]), Table1[Status ] = "Started")
    VAR JobEnd = CALCULATE(MAX(Table1[Activity Time]), Table1[Status ] = "Stopped")
RETURN
CALCULATE(
    DATEDIFF(JobStart,JobEnd,MINUTE) - DATEDIFF(BreakStart,BreakEnd,MINUTE)
)

 

TableResult.pngdatediff table.png

PS: Ignore the 'DocEntry' figure, forgot to remove the quick sum calc 😁

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.

Top Solution Authors