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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KartheekJ
Frequent Visitor

Calculating active employees in each month of a year using hire date and end date columns

Hi,

 

I have an employee table with hire date and end date columns and a date table.

There is an active relation between Date[date] and Employee[end date] and an inactive relation between Date[date] and Employee[hire date].

The requirement is to show no of active employees in each month of the year in a column chart.

I have used the below DAX formula

Active Employees =
CALCULATE(
    [No.of Resources],
    'BM EXTERNALS TRACKED DATA'[Hire Date ] <= MAX('Date'[Date]),
    'BM EXTERNALS TRACKED DATA'[End Date ] >= MIN('Date'[Date]),
    USERELATIONSHIP('BM EXTERNALS TRACKED DATA'[Hire Date ],'Date'[Date])
)
and got the below outcome which is wrong
KartheekJ_0-1728995268977.png

 

Then, I have tried this Dax formula 

Head Count = CALCULATE(
                              [No.of Resources],
                              FILTER(
                                  ALL('Date'),
                                 'Date'[Date] >= MIN('Date'[Date])
                              )
                       )
 
and got below outcome
KartheekJ_1-1728995465376.png

This is a bette outcome.

 

But, the issue is this formula is not considering the hire date while calculating active resources.

 

for example, if an employee has a start date as 10/04/24 and end date as 31/07/24, he should only be included in the active employees in April, May, June and July. he shouldn't be included for the months before april 2024.

 

But this 2nd formula is including the above employee in every month till Jul 24.

 

Can someone help me to modify the DAX to calculate active employees considering both hire date and end date.

 

Thanks

Kartheek

        
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @KartheekJ ,

 

Regarding this topic, the key to solving your headcount issue is to set your calendar (date) table as a disconnected table from your employee table, which contains information such as employee ID, joining date, and leaving date. Then, you can write a DAX formula like the one below, enabling you to calculate headcount at any point in time!

Headcount =
SUMX (
    EmployeeFact,
    IF (
        EmployeeFact[Start] <= [SelectedDate]
            && EmployeeFact[End] >= [SelectedDate],
        1,
        BLANK ()
    )
)

Please refer to the article below if you’d like to explore this topic further.

https://community.fabric.microsoft.com/t5/Community-Blog/Dynamic-Headcount-Analysis-using-Dax/ba-p/4...

 

Best regards,

View solution in original post

2 REPLIES 2
KartheekJ
Frequent Visitor

Hi @DataNinja777.  Thank you very much for the quick response.

DataNinja777
Super User
Super User

Hi @KartheekJ ,

 

Regarding this topic, the key to solving your headcount issue is to set your calendar (date) table as a disconnected table from your employee table, which contains information such as employee ID, joining date, and leaving date. Then, you can write a DAX formula like the one below, enabling you to calculate headcount at any point in time!

Headcount =
SUMX (
    EmployeeFact,
    IF (
        EmployeeFact[Start] <= [SelectedDate]
            && EmployeeFact[End] >= [SelectedDate],
        1,
        BLANK ()
    )
)

Please refer to the article below if you’d like to explore this topic further.

https://community.fabric.microsoft.com/t5/Community-Blog/Dynamic-Headcount-Analysis-using-Dax/ba-p/4...

 

Best regards,

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.