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
DarshanKumar
Helper I
Helper I

Calculating Active Employees by specific Date

Hi,

Im trying to calculate the active employees by month. My employee table has duplicate values , multiple rows  of data for an employee. Each row has the same start date and end date and job information date. Job information date changes when ever the employee chnaged the department.

 

Below is the Dax formula i have used. But the active employee count measure  is not counting it corretcly  on those months when the employee has changed department. Any help is highly appreciated

 

ActiveEmployeesCount =
VAR thisdate = MAX(CalenderTable[Date])
RETURN
CALCULATE(
    DISTINCTCOUNT('Job Information'[Employee #]),
    FILTER(
        'Job Information',
        'Job Information'[Hire Date].[Date] <= thisdate &&
        (ISBLANK('Job Information'[Terminaion Date]) || 'Job Information'[Terminaion Date].[Date]>thisdate)
    )
1 ACCEPTED SOLUTION

Hello @DarshanKumar,

 

Can you please try this approach:

ActiveEmployeesPerDepartment =
VAR SelectedMonth =
    MAX('Calendar'[Date])
RETURN
CALCULATE (
    DISTINCTCOUNT ( 'Job Information'[Emp ID] ),
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                'Job Information',
                'Job Information'[Emp ID],
                'Job Information'[Department],
                "LatestChange",
                    CALCULATE (
                        MAX ( 'Job Information'[Job Information: Date] ),
                        FILTER (
                            'Job Information',
                            'Job Information'[Emp ID] = EARLIER('Job Information'[Emp ID]) &&
                            'Job Information'[Department] = EARLIER('Job Information'[Department]) &&
                            'Job Information'[Job Information: Date] <= SelectedMonth
                        )
                    )
            ),
            "HireCheck", CALCULATE (
                MIN ( 'Job Information'[Hire Date] )
            ),
            "TermCheck", CALCULATE (
                MAX ( 'Job Information'[Terminaion Date] )
            )
        ),
        [HireCheck] <= SelectedMonth &&
        (ISBLANK([TermCheck]) || [TermCheck] > SelectedMonth)
    )
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

5 REPLIES 5
DarshanKumar
Helper I
Helper I

@Sahir_Maharaj  Thank you very much it worked. Im a new bie in Dax and power BI. Thank you very much for your help.

DarshanKumar
Helper I
Helper I

@Sahir_Maharaj  thanks. I will check and come back to you.

 

Regards,

Darshan

DarshanKumar
Helper I
Helper I

@Greg_Deckler  Thansk for your promopt response. Please find the table. My requirement is to calculate active employees permonth. but I have duplicates in the employee table as some of the employees have changed department and I would need  active employees by department  for the selected month.

 

Emp IDHire DateJob Information: DateLocationDepartmentTerminaion Date
05301/08/202001/03/2019LuxembourgCorporate Services [CSVC]30/06/2022
00040102/02/202401/11/2024LondonRegulatory and Compliance 
00040102/02/202415/08/2024LondonRegulatory and Compliance 
00040102/02/202429/05/2024LondonRegulatory and Compliance 
00040102/02/202422/05/2023LondonRegulatory and Compliance 
15342803/02/202503/02/2025MauritiusGlobal Operations 
15251902/05/202301/01/2025MauritiusGlobal Operations03/03/2025
15251902/05/202307/08/2024MauritiusCorporate Services03/03/2025
15251902/05/202310/05/2024MauritiusCorporate Services03/03/2025
15251902/05/202301/03/2024MauritiusCorporate Services03/03/2025
15251902/05/202302/05/2023MauritiusCorporate Services03/03/2025
15244420/03/202301/03/2025MauritiusCorporate Services 
15244420/03/202301/01/2025MauritiusGlobal Operations 
15244420/03/202302/12/2024MauritiusCorporate Services 
15244420/03/202301/03/2024MauritiusCorporate Services 
15244420/03/202320/04/2023MauritiusCorporate Services 
15244420/03/202320/03/2023MauritiusCorporate Services 
20601801/06/200601/03/2023MauritiusPrivate Clients 
20601801/06/200616/01/2023MauritiusCorporate Services 
20601801/06/200610/01/2022MauritiusCorporate Services 
20601801/06/200601/09/2020MauritiusCorporate Services [CSVC] 
20601801/06/200601/06/2006MauritiusCorporate 
15258305/06/202320/02/2025MauritiusGlobal Operations 
15258305/06/202301/11/2024MauritiusGlobal Operations 
15258305/06/202301/03/2024MauritiusGlobal Operations 
15258305/06/202312/01/2024MauritiusGlobal Operations 
15258305/06/202329/11/2023MauritiusGlobal Operations 
15258305/06/202305/06/2023MauritiusGlobal Operations 
15331828/10/202420/11/2024MauritiusFinance 
15331828/10/202408/11/2024MauritiusFinance 
57714/05/201814/05/2018JerseyPrivate Clients20/10/2021
03601/07/201614/08/2024LuxembourgCorporate Services 
03601/07/201601/03/2024LuxembourgCorporate Services 
03601/07/201610/01/2022LuxembourgCorporate Services 
03601/07/201601/09/2021LuxembourgCorporate Services [CSVC] 

Hello @DarshanKumar,

 

Can you please try this approach:

ActiveEmployeesPerDepartment =
VAR SelectedMonth =
    MAX('Calendar'[Date])
RETURN
CALCULATE (
    DISTINCTCOUNT ( 'Job Information'[Emp ID] ),
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                'Job Information',
                'Job Information'[Emp ID],
                'Job Information'[Department],
                "LatestChange",
                    CALCULATE (
                        MAX ( 'Job Information'[Job Information: Date] ),
                        FILTER (
                            'Job Information',
                            'Job Information'[Emp ID] = EARLIER('Job Information'[Emp ID]) &&
                            'Job Information'[Department] = EARLIER('Job Information'[Department]) &&
                            'Job Information'[Job Information: Date] <= SelectedMonth
                        )
                    )
            ),
            "HireCheck", CALCULATE (
                MIN ( 'Job Information'[Hire Date] )
            ),
            "TermCheck", CALCULATE (
                MAX ( 'Job Information'[Terminaion Date] )
            )
        ),
        [HireCheck] <= SelectedMonth &&
        (ISBLANK([TermCheck]) || [TermCheck] > SelectedMonth)
    )
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Greg_Deckler
Community Champion
Community Champion

@DarshanKumar Can you provide sample data as text?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.