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
vananh_nguyen
Regular Visitor

DAX to count number of employees by the end of a year

I'm having trouble understanding why the DAX measure doesn't return the expected results.

 

I have 2 tables:

 

- Calendar Years which lists the years from 2019 - 2023

- Hire: includes transactions when an employee was first hired or rehired into a high-ranking position that we tracked (say Position A). This table was previously merged with another table, Resignation, indicating the Projected Resignation date from position A, NOT from the organization. The Projected Resignation Date can include a date in the past even though an employee is still active in position A. In this case, it means that the employee was rehired into position A, and the table still contains the old record of the last resignation date from position A. The table has a Termination Date to indicate when the employee left the organization. The Termination Date is null if the employee is active.

 

Hiring Table - Example of an employee

Hire YearHire DateEmployee IDTermination DateProjected Resignation Date
200601-15-200612345null06-20-2009
201703-31-201712345null06-20-2009

 

Relationships:

 

- The Calendar and Hiring table joined together using Hire Year.

 

DAX Measure and Problem:

 

- I used the following measure to calculate the number of active employees for position A by the end of each year (2019-2023). Using the above example, I would expect there will be 2 counts for Employee ID 12345, however, the table only shows 1 count.  1 count is the correct result, I just wanted to understand why it turned out to be 1 and not 2. I'm still fairly new to DAX so perhaps I misunderstood some logic here. Thank you so much for your help!

 

 

Active Employee at End of Year = 
VAR CurrentYear = MAX('Calendar Years'[Year])  // Get the current year from the calendar year table
VAR EmpCount =
    CALCULATE(
        COUNTROWS(
            CALCULATETABLE( 'Hire', 'Hire'[Hire Year] <= CurrentYear, ALL('Calendar Years'[Year]))
        ),
        (ISBLANK('Hire'[Projected Separation Date]) || 'Hire'[Projected Separation Date] > DATE(CurrentYear, 12, 31) ||
        ('Hire'[Projected Separation Date] <= DATE(CurrentYear, 12,31) && 'Hire'[Action Start Date] > 'Hire'[Projected Separation Date])
        )
    )
RETURN
EmpCount

 

 

This is the table I have as a result of the above DAX measure. The 'Year' column is from the 'Calendar Year' table.

 

YearNumber of Employees at End of Year
20191
20201
20211
20221
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You have a granularity mismatch between employee details (day level) and reporting needs (year level).  As you indicate you can solve that by affixing your year to a date (last day of year).  Most likely you need to keep these tables disconnected. But you should not need to have separate hire and resignation tables. That should be a single table with employee ID, start date and (optional) end date.  Then you can do a DISTINCTCOUNT on the employee ID (assuming they get the same ID when they get rehired).

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

You have a granularity mismatch between employee details (day level) and reporting needs (year level).  As you indicate you can solve that by affixing your year to a date (last day of year).  Most likely you need to keep these tables disconnected. But you should not need to have separate hire and resignation tables. That should be a single table with employee ID, start date and (optional) end date.  Then you can do a DISTINCTCOUNT on the employee ID (assuming they get the same ID when they get rehired).

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.