Formula Generator | DAX

Employee Punch Time Separation in DAX

This guide details a DAX solution to create a calculated table that separates employee punch-in and punch-out times using a dataset of employee codes and timestamps, employing functions like SUMMARIZE, CALCULATE, MIN, and MAX.


Empty image or helper icon

Prompt

i have shet having data as employee code & time, Emp. Code	Time
1503	15-08-2024 12:46
1515	15-08-2024 13:54
1515	15-08-2024 14:18
1581	15-08-2024 12:19
1602	15-08-2024 13:26
1640	15-08-2024 14:09
1812	15-08-2024 12:31
2029	15-08-2024 12:31
i need output as below Emp. Code	Punch IN Time	Punch OUT Time
1503	15-08-2024 12:46	
1515	15-08-2024 13:54	15-08-2024 14:18
1581	15-08-2024 12:19	
1602	15-08-2024 13:26	
1640	15-08-2024 14:09	
1812	15-08-2024 12:31	
2029	15-08-2024 12:31	
2073	15-08-2024 13:32	
2296	15-08-2024 13:21	15-08-2024 13:48
2368	15-08-2024 13:47	15-08-2024 14:19
It seperates the in time & out time employee id wise how i cna do that

Answer

DAX Solution for Employee Punch In and Punch Out Times

Objective

To create a DAX calculated table that separates employee punch-in and punch-out times from a given dataset of employee codes and timestamps.

Data Structure

The input dataset consists of the following columns:

  • Emp. Code
  • Time

Example Input Data

Emp. Code Time
1503 15-08-2024 12:46
1515 15-08-2024 13:54
1515 15-08-2024 14:18
1581 15-08-2024 12:19
1602 15-08-2024 13:26
1640 15-08-2024 14:09
1812 15-08-2024 12:31
2029 15-08-2024 12:31

DAX Formula

To achieve the desired output, the following DAX formula will create a calculated table:

PunchTimes = 
VAR SummaryTable = 
    SUMMARIZE (
        'YourDataTable',
        'YourDataTable'[Emp. Code],
        "Punch IN", 
            CALCULATE (
                MIN ( 'YourDataTable'[Time] ),
                ALLEXCEPT ( 'YourDataTable', 'YourDataTable'[Emp. Code] )
            ),
        "Punch OUT", 
            CALCULATE (
                MAX ( 'YourDataTable'[Time] ),
                ALLEXCEPT ( 'YourDataTable', 'YourDataTable'[Emp. Code] )
            )
    )
RETURN
    SummaryTable

Explanations:

  1. SUMMARIZE: This function creates a new table by grouping data. The groups are created by the Emp. Code.

  2. CALCULATE: This function changes the context in which data is evaluated. In this case, it calculates the minimum and maximum time entries separated by Punch IN and Punch OUT.

  3. MIN: Used to find the earliest timestamp for each employee which is recorded as Punch IN.

  4. MAX: Used to find the latest timestamp for each employee which is recorded as Punch OUT.

  5. ALLEXCEPT: This function maintains the context for the Emp. Code while removing other filters, thus ensuring calculations are done per employee.

Practical Example

Assuming the input data is in a table named EmployeeTimes, executing the above DAX results in a table that displays:

Emp. Code Punch IN Punch OUT
1503 15-08-2024 12:46
1515 15-08-2024 13:54 15-08-2024 14:18
1581 15-08-2024 12:19
1602 15-08-2024 13:26
1640 15-08-2024 14:09
1812 15-08-2024 12:31
2029 15-08-2024 12:31

Conclusion

The provided DAX formula accurately separates punch-in and punch-out times based on the employee codes. By using functions like SUMMARIZE, CALCULATE, MIN, and MAX, the solution outlines a structured approach to achieving the desired output within a Power BI context. For further mastery of DAX concepts, consider exploring relevant courses offered on the Enterprise DNA Platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This guide details a DAX solution to create a calculated table that separates employee punch-in and punch-out times using a dataset of employee codes and timestamps, employing functions like SUMMARIZE, CALCULATE, MIN, and MAX.