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
Anonymous
Not applicable

Date&Time differences between rows in same column

Hello ladies and gentlemen,

 

once again I need your help. 

I have following challenge.

I have a time and attendance table which gives me the login data of an employee (Workerpersonallnumber) per day. I have a column where i see whether the employee logged in or logged out. 

 

image.png

 

The expected outcome is to have a duration of logged in hours per employee per day/shift.

 

I tried to solve it with two different tables - one signin and one signout one - but i didnt get a connection that would link those two.

 

Your help is as always highly appreciated.

Thanks in advance.

 

Best regards,

Paul

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I build following columns.image.png

 

How do i get PowerBI to calculate chronologically the duration between each sign in and sign out by employee?

 

View solution in original post

3 REPLIES 3
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a date column and a measure to meet your requirement.

 

1. Create a date column in table.

 

Date = DATE(YEAR('Table'[StartDateTime]),MONTH('Table'[StartDateTime]),DAY('Table'[StartDateTime]))

 

Date1.jpg

 

2. Then we can create a measure like this,

 

Hours = 
VAR sign_in =
    CALCULATE (
        MIN ( 'Table'[StartDateTime] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Type] = "signin"
                && 'Table'[Date] = MAX ( 'Table'[Date] )
                && 'Table'[WorkerNumber] = MAX ( 'Table'[WorkerNumber] )
        )
    )
VAR sign_out =
    CALCULATE (
        MAX ( 'Table'[StartDateTime] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Type] = "signOut"
                && 'Table'[Date] = MAX ( 'Table'[Date] )
                && 'Table'[WorkerNumber] = MAX ( 'Table'[WorkerNumber] )
        )
    )
RETURN
DATEDIFF ( sign_in, sign_out, HOUR )

 

Date2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.       

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Not all heroes were capes....  thank you very much. It works perfect. 

Anonymous
Not applicable

I build following columns.image.png

 

How do i get PowerBI to calculate chronologically the duration between each sign in and sign out by employee?

 

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.