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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Identifying if a Record has ended using start and end dates of table

Hi There,

 

I'm new to PowerBi and am trying to identify if an employee has left the organization vs those that have transferred roles. My table contains the employee ID, job code, start date for that role and end date for that role where the end date is blank if they are a current employee.

 

I would like to use Dax to add an additional column to label all terminated employees - these are employees no longer with the company or have left and returned more than 14 days after the end date of the role..  I have attached table of with a sample of data.  Where 'expected Values' si what I'm hopgin to use my Dax formula with.

 

In my example,Employee 1 has transferred to a new role effective April 5th(end date of previous role was on Friday and they start the new role on Monday).  So even though Line 1 has an end date, I do not want them to be labelled as terminated.  However,  Because employee 2 ended on March 31, 2021 and came back the next year, they should be considered terminated effective march 31, 2021.  (The buffer period between the end date of one line and start date of another line for the same employee should be 14 days).  

 

Employee IDJob CodeStart DateEnd DateExpected Values
1A1/1/20214/2/2021 
1B4/5/2021  
2B2/2/20213/31/2021Left Organization
2B1/1/2022  
3A2/1/20213/31/2022Left Organization
4A2/2/2022  

 

Hoping Someone will be able to help me.  Thanks in Advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try this code to create a calculated column.

Flag =
VAR _COUNT =
    CALCULATE (
        COUNT ( Employee[Employee ID] ),
        ALLEXCEPT ( Employee, Employee[Employee ID] )
    )
VAR _NEXTSTARTDATE =
    CALCULATE (
        MIN ( Employee[Start Date] ),
        FILTER (
            ALLEXCEPT ( Employee, Employee[Employee ID] ),
            Employee[Start Date] > EARLIER ( Employee[End Date] )
        )
    )
VAR _DATEDIFF =
    DATEDIFF ( Employee[End Date], _NEXTSTARTDATE, DAY )
RETURN
    IF (
        _COUNT = 1,
        IF ( Employee[End Date] = BLANK (), BLANK (), "Left organization" ),
        IF ( _DATEDIFF < 14, BLANK (), "Left organization" )
    )

Result is as below.

RicoZhou_0-1658306081619.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try this code to create a calculated column.

Flag =
VAR _COUNT =
    CALCULATE (
        COUNT ( Employee[Employee ID] ),
        ALLEXCEPT ( Employee, Employee[Employee ID] )
    )
VAR _NEXTSTARTDATE =
    CALCULATE (
        MIN ( Employee[Start Date] ),
        FILTER (
            ALLEXCEPT ( Employee, Employee[Employee ID] ),
            Employee[Start Date] > EARLIER ( Employee[End Date] )
        )
    )
VAR _DATEDIFF =
    DATEDIFF ( Employee[End Date], _NEXTSTARTDATE, DAY )
RETURN
    IF (
        _COUNT = 1,
        IF ( Employee[End Date] = BLANK (), BLANK (), "Left organization" ),
        IF ( _DATEDIFF < 14, BLANK (), "Left organization" )
    )

Result is as below.

RicoZhou_0-1658306081619.png

 

Best Regards,
Rico Zhou

 

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

Anonymous
Not applicable

Thanks @Anonymous!  I jsut tested this and it does what I needed!

johnt75
Super User
Super User

You can try

Left company =
VAR currentEmployeeID = 'Employee'[Employee ID]
VAR currentEndDate = 'Employee'[End Date]
VAR futureJobs =
    FILTER (
        'Employee',
        'Employee'[ID] = currentEmployeeID
            && 'Employee'[Start Date] <= currentEndDate + 14
    )
RETURN
    IF (
        NOT ( ISBLANK ( currentEndDate ) ) && ISEMPTY ( futureJobs ),
        "Left organization"
    )

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.