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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
RichOB
Post Partisan
Post Partisan

Day count calculated column

Hi, I posted something similar recently, but I need a different variation on it, please.

 

Using the table below, I'd like to get a column that shows the day count from the Date_Left to the Date_Joined for each employee. This will show how long they were away before rejoining us. Thanks.

 

NI_NumberNameTitleDate_JoinedDate_LeftDays_EmployedDays_Between (Previous employment and most recent. This is the column I need)
NI112233Dave JonesCustomer Service01/04/202420/05/202449 
NI112233Dave JonesCustomer Service01/06/202410/06/2024912
NI884455Eric DaviesCustomer Service01/07/202410/10/2024101 
NI884455Eric DaviesCustomer Service20/10/202428/10/2024810
NI009900Lloyd Williams Store Manager01/04/202410/09/202490 
NI009900Lloyd Williams Store Manager01/10/202411/11/20244121
NI887711Ian IansStore Manager10/05/202410/10/2024153 
NI887711Ian IansStore Manager01/11/2024 30326
1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @RichOB 
If you need just calculation you can use a dax formula:

DaysBetween... =

var start_ = CALCULATE(MIN('Table'[Date_Left]),ALLEXCEPT('Table','Table'[NI_Number]))

var end_ = CALCULATE(MAX('Table'[Date_Joined]),ALLEXCEPT('Table','Table'[NI_Number]))

Return end_-start_
Ritaf1983_0-1758616706119.png

If you need a result only at the last row on employee level the formula is :

Days_Between_LastOnly =

VAR Emp       = 'Table'[NI_Number]

VAR LastJoin  =

    CALCULATE(

        MAX('Table'[Date_Joined]),

        FILTER('Table', 'Table'[NI_Number] = Emp)

    )

VAR PrevLeft  =

    CALCULATE(

        MAX('Table'[Date_Left]),

        FILTER('Table',

            'Table'[NI_Number] = Emp &&

            'Table'[Date_Left] < LastJoin

        )

    )

VAR IsLastRow = 'Table'[Date_Joined] = LastJoin

RETURN

    IF(IsLastRow,

        DATEDIFF(PrevLeft, LastJoin, DAY),

        BLANK()

    )

The pbix with the example is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
v-saisrao-msft
Community Support
Community Support

Hi @RichOB,

Have you had a chance to review the solution we shared by @Ritaf1983 @AnkitaaMishra? If the issue persists, feel free to reply so we can help further.

 

Thank you.

Ritaf1983
Super User
Super User

Hi @RichOB 
If you need just calculation you can use a dax formula:

DaysBetween... =

var start_ = CALCULATE(MIN('Table'[Date_Left]),ALLEXCEPT('Table','Table'[NI_Number]))

var end_ = CALCULATE(MAX('Table'[Date_Joined]),ALLEXCEPT('Table','Table'[NI_Number]))

Return end_-start_
Ritaf1983_0-1758616706119.png

If you need a result only at the last row on employee level the formula is :

Days_Between_LastOnly =

VAR Emp       = 'Table'[NI_Number]

VAR LastJoin  =

    CALCULATE(

        MAX('Table'[Date_Joined]),

        FILTER('Table', 'Table'[NI_Number] = Emp)

    )

VAR PrevLeft  =

    CALCULATE(

        MAX('Table'[Date_Left]),

        FILTER('Table',

            'Table'[NI_Number] = Emp &&

            'Table'[Date_Left] < LastJoin

        )

    )

VAR IsLastRow = 'Table'[Date_Joined] = LastJoin

RETURN

    IF(IsLastRow,

        DATEDIFF(PrevLeft, LastJoin, DAY),

        BLANK()

    )

The pbix with the example is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
AnkitaaMishra
Super User
Super User

Hi @RichOB , Could you please try below DAX:

Days_Between =
VAR CurrentEmployee = Employees[NI_Number]
VAR CurrentJoinDate = Employees[Date_Joined]
VAR PreviousLeftDate =
    LOOKUPVALUE(
        Employees[Date_Left],
        Employees[NI_Number], CurrentEmployee,
        Employees[Date_Left],
        MAXX(
            FILTER(
                Employees,
                Employees[NI_Number] = CurrentEmployee &&
                Employees[Date_Left] < CurrentJoinDate
            ),
            Employees[Date_Left]
        )
    )
RETURN
IF(
    ISBLANK(PreviousLeftDate),
    BLANK(),
    DATEDIFF(PreviousLeftDate, CurrentJoinDate, DAY)
)

AnkitaaMishra_0-1758616570428.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors