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

Employee count with changing records

Hi PBI community, 

 

I'm struggling with what I thought was easy lol.

First, I want you to know that have read multiple post and tried to figure what is different from my model, but I can not find what I'm doing wrong. 

Here is the problem: 

I need to generate the count of active employees at a selected month/date. In the data set there are multiple records per employee that represent changes in positions or locations; those are identified by different Record_Date

 

Here is a sample data

IDHire DateTermination DateStatus_CodeRecord Date
326172/4/2019 A11/16/2021
326172/4/2019 A9/20/2022
326172/4/2019 A11/17/2022
326172/4/20191/12/2023T1/13/2023
326313/28/2011 A7/22/2020
326313/28/2011 A11/18/2020
326313/28/2011 A6/9/2021
326313/28/2011 A11/16/2021
326313/28/2011 L2/23/2021
326313/28/20112/25/2022T2/26/2022
80197410/15/2018 A6/9/2021
80197410/15/2018 A11/16/2021
80197410/15/2018 A2/23/2021
80197410/15/201811/3/2022T11/15/2022
8017774/17/2017 A4/20/2017
8017774/17/2017 A11/1/2019
8017774/17/20179/1/2022T9/15/2022
8017805/1/2017 A6/1/2017
8017805/1/2017 A8/3/2020
8017694/20/2017 A4/20/2017
8017694/20/2017 A11/1/2019
8017694/20/2017 A9/15/2022
8017684/3/2018 A4/30/2018
8017684/4/2018 A5/30/2021
8017673/29/2017 A4/1/2017
8017673/29/2017 A9/2/2022

 

To use time intelligence, I joined Calendar table and the Employee table with inactive relationship in 'Hire Date' and 'Termination Date' with 'Date' from the calendar table.

viviarc_0-1681163683571.png

 

The dax I'm using is as: 

 

 

Empl_Count_ = 
var maxdate = max('Calendar'[Date])
var empltotalcount =  CALCULATE(DISTINCTCOUNT('Employee'[ID]) , Employee[Status_Code] <> "T" )
var result = 
    CALCULATE(
        empltotalcount,
        REMOVEFILTERS('Calendar'),
        'Employee'[Hire Date] <= maxdate
        ,'Employee'[Termination Date] > maxdate || ISBLANK(Employee[Termination Date])
    )
Return
    result

 

 

 

Unfortunatelly the dax I'm using is counting all employees with out considering change in status.

 

This is the expected result: 

If select Dec 2022, Empl_Count = 5
If select Jan 2023, Empl_Count = 4
If select Aug 2022, Empl_Count = 7
If select full year 2022, Empl_Count = 8

 

TIA for all your help!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, 

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1681184331053.png

 

Jihwan_Kim_1-1681184836711.png

 

Active employee count measure: = 
VAR _latestrecorddate =
    GROUPBY (
        Employee,
        Employee[ID],
        "@latestrecord", MAXX ( CURRENTGROUP (), Employee[Record Date] )
    )
VAR _latestrecordinfo =
    CALCULATETABLE (
        Employee,
        TREATAS ( _latestrecorddate, Employee[ID], Employee[Record Date] )
    )
VAR _resulttable =
    FILTER (
        _latestrecordinfo,
        Employee[Hire Date] <= MAX ( 'Calendar'[Date] )
            && OR (
                Employee[Termination Date] = BLANK (),
                Employee[Termination Date] >= MIN ( 'Calendar'[Date] )
            )
    )
RETURN
    COUNTROWS ( _resulttable )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, 

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1681184331053.png

 

Jihwan_Kim_1-1681184836711.png

 

Active employee count measure: = 
VAR _latestrecorddate =
    GROUPBY (
        Employee,
        Employee[ID],
        "@latestrecord", MAXX ( CURRENTGROUP (), Employee[Record Date] )
    )
VAR _latestrecordinfo =
    CALCULATETABLE (
        Employee,
        TREATAS ( _latestrecorddate, Employee[ID], Employee[Record Date] )
    )
VAR _resulttable =
    FILTER (
        _latestrecordinfo,
        Employee[Hire Date] <= MAX ( 'Calendar'[Date] )
            && OR (
                Employee[Termination Date] = BLANK (),
                Employee[Termination Date] >= MIN ( 'Calendar'[Date] )
            )
    )
RETURN
    COUNTROWS ( _resulttable )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi Jihwan_Kim, 
What you provided is fantastic, thank you so much. 
Have another question: if want to count active employees based on the previous to the last 'Record Date', how will the measure you share will change?
Do need to sustract a month? sorry for the question, hope is not confusing. 

 

Thank again! 

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.