Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Luca2020
Helper I
Helper I

Employees Stamp

Hi, 

I have a table with the daily entry and exit records for each employee. 

empl_id       datetype
103629/12/2022 14:08IN
103629/12/2022 22:08OUT
103631/12/2022 07:21IN
103631/12/2022 12:44OUT

 

I would prefer to have a table with the entry and exit records as different columns instead.

empl_id          entry        exit h
103629/12/2022 14:0829/12/2022 22:08 8
103631/12/2022 07:2131/12/2022 12:44 5

 

Some employees work at night so they start one day and finish the next one. 

 

Can someone help me? 

Thanks

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

@Luca2020 
Please try the following query.

Actually I'm dealing with an attendance data that is much more complex than yours. I tried to simplify for your case. Hope it works.

AttendanceNew =
VAR T1 =
    SELECTCOLUMNS (
        FILTER ( AttendanceSource, AttendanceSource[tipologia] = "IN" ),
        "Emp.No.", AttendanceSource[empl_id],
        "@Date", DATEVALUE ( AttendanceSource[datd] ),
        "ClockIn", AttendanceSource[data]
    )
VAR T2 =
    SELECTCOLUMNS (
        FILTER ( AttendanceSource, AttendanceSource[tipologia] = "OUT" ),
        "Emp.No.1", AttendanceSource[empl_id],
        "ClockOut", AttendanceSource[data]
    )
VAR T3 =
    GENERATE (
        T1,
        VAR TimeIn = [ClockIn]
        VAR DateIn =
            DATEVALUE ( TimeIn )
        VAR T4 =
            FILTER ( T2, [Emp.No.1] = [Emp.No.] && [ClockOut] > TimeIn )
        VAR T5 =
            FILTER ( T4, DATEVALUE ( [ClockOut] ) = DateIn )
        VAR T6 =
            FILTER ( T4, DATEVALUE ( [ClockOut] ) = DateIn + 1 )
        VAR ClockOut1 =
            MAXX ( T5, [ClockOut] )
        VAR ClockOut2 =
            MINX ( T6, [ClockOut] )
        VAR ClockOut =
            COALESCE ( ClockOut1, ClockOut2 )
        RETURN
            ROW ( "ClockOut", ClockOut )
    )
RETURN
    T3

 

View solution in original post

3 REPLIES 3
tamerj1
Community Champion
Community Champion

@Luca2020 
Please try the following query.

Actually I'm dealing with an attendance data that is much more complex than yours. I tried to simplify for your case. Hope it works.

AttendanceNew =
VAR T1 =
    SELECTCOLUMNS (
        FILTER ( AttendanceSource, AttendanceSource[tipologia] = "IN" ),
        "Emp.No.", AttendanceSource[empl_id],
        "@Date", DATEVALUE ( AttendanceSource[datd] ),
        "ClockIn", AttendanceSource[data]
    )
VAR T2 =
    SELECTCOLUMNS (
        FILTER ( AttendanceSource, AttendanceSource[tipologia] = "OUT" ),
        "Emp.No.1", AttendanceSource[empl_id],
        "ClockOut", AttendanceSource[data]
    )
VAR T3 =
    GENERATE (
        T1,
        VAR TimeIn = [ClockIn]
        VAR DateIn =
            DATEVALUE ( TimeIn )
        VAR T4 =
            FILTER ( T2, [Emp.No.1] = [Emp.No.] && [ClockOut] > TimeIn )
        VAR T5 =
            FILTER ( T4, DATEVALUE ( [ClockOut] ) = DateIn )
        VAR T6 =
            FILTER ( T4, DATEVALUE ( [ClockOut] ) = DateIn + 1 )
        VAR ClockOut1 =
            MAXX ( T5, [ClockOut] )
        VAR ClockOut2 =
            MINX ( T6, [ClockOut] )
        VAR ClockOut =
            COALESCE ( ClockOut1, ClockOut2 )
        RETURN
            ROW ( "ClockOut", ClockOut )
    )
RETURN
    T3

 

tamerj1
Community Champion
Community Champion

Hi @Luca2020 

Do you have double punches or your data is just as clean as this sample?

This is my database,

I have all the daily In and Out records for each employee,

the difficult part is when workers start one day and finish the next one, and start a new shift later on the same day.

ScreenHunter 439.png

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.