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
stefani_vileva
Resolver II
Resolver II

Calculating breaks in working time

Hello everyone,

 

I have problem solving the time duration between times of two different rows. For example, I have the following table:

 

DateNameDepartmentComingGoing
13.06.2022Stefani VilevaSales15:0016:00
13.06.2022Stefani VilevaSales10:0014:45
13.06.2022Stefani VilevaSales08:0009:35

 

My goal is to calculate the time of the breaks between this working times, i.e. I have break from 09:35 - 10:00 which is 25 minutes break and 14:45 - 15:00, 15 minutes break. I don't want to find the overall break time for example in our case 40 minutes, but for every break individually.

 

Thanks in advance.

 

Kind regards,

Stefani Vileva

1 ACCEPTED SOLUTION
FarhanAhmed
Community Champion
Community Champion

you can create a calculated column to get the Last out for particular day and then take the difference between 2 times

 

Last Out = 
Var dt = 'Table'[Date]
Var nm = 'Table'[Name]
Var dpt = 'Table'[Department]
var cmg = 'Table'[Coming]
RETURN 

CALCULATE(MAX('Table'[Going]),FILTER('Table','Table'[Date]=dt && 'Table'[Name]=nm && 'Table'[Department]=dpt && 'Table'[Coming]<cmg ))

FarhanAhmed_0-1655271407709.png

 







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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
FarhanAhmed
Community Champion
Community Champion

you can create a calculated column to get the Last out for particular day and then take the difference between 2 times

 

Last Out = 
Var dt = 'Table'[Date]
Var nm = 'Table'[Name]
Var dpt = 'Table'[Department]
var cmg = 'Table'[Coming]
RETURN 

CALCULATE(MAX('Table'[Going]),FILTER('Table','Table'[Date]=dt && 'Table'[Name]=nm && 'Table'[Department]=dpt && 'Table'[Coming]<cmg ))

FarhanAhmed_0-1655271407709.png

 







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

Proud to be a Super User!




 

Time Diff = IF(ISBLANK('Table'[Last Out]),BLANK(),'Table'[Coming]-'Table'[Last Out])

FarhanAhmed_1-1655271500418.png

 







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

Proud to be a Super User!




Hello @FarhanAhmed 

 

Thanks a lot, it solved my problem.

 

Kind regards,

Stefani

 

 

Samarth_18
Community Champion
Community Champion

Hi @stefani_vileva ,

 

You need to create a index column from the power query then you can create a column as below:-

Column =
VAR _current_index = [Index]
VAR _prev_index = [Index] - 1
VAR _coming_time =
    CALCULATE (
        MAX ( 'Table (3)'[Coming] ),
        FILTER (
            'Table (3)',
            'Table (3)'[Index] = _prev_index
                && 'Table (3)'[Date] = EARLIER ( 'Table (3)'[Date] )
                && 'Table (3)'[Name] = EARLIER ( 'Table (3)'[Name] )
        )
    )
RETURN
    DATEDIFF ( 'Table (3)'[Going], _coming_time, MINUTE )

Output:-

Samarth_18_0-1655270797117.png

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.