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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Anonymous
Not applicable

Evaluate Headcount Table (SCD type II) for Trending Headcount

Hi Team, 

 

Here's a snippet of three tables I have, one is a basic calendar table, with date, endofweek, and endofmonth and the second on is a employee table that's a slow changing dimension type II table, meaning each time there's a 'transaction' with an employee a new record gets inserted into the table. There's a relationship between the two yellow columns. The last table, circled in blue, is the result I'm struggling with. 

My challenge is I'm trying to evaluate when an employee was 'active' over time, on the last day of every month, while taking in considersation their status, and count them 'active' for that month. 

Example if you start to look at the table in the middle, this employees career started in Oct 2022 and then it was terminated on May 2023, then they were rehired back on the following month in June and they're 'active' until the most recent record in Oct 2024. In this example this employee would be counted 'active' at the end of every month from Oct 2022 to Oct 2024, except when they were terminated in May 2023. My DAX measure isn't counting them correctly as you can see in the table on the right. Below is my current measure I'm using, and I can't seem to figure out the solution. 

 

Trending Headcount = 

VAR MaxDate = MAX('Date'[EndOfMonth])
RETURN
CALCULATE(
    DISTINCTCOUNT(Emp[EMP_ID]),  
    Emp[EFF_TMSTP] <= MaxDate && Emp[EMP_STATUS] = "Active")

 

Any help with this measure would be greatly appreciated and happy to provide more context if needed. 

 

snippet.png

4 REPLIES 4
powerbiexpert22
Impactful Individual
Impactful Individual

Hi @Anonymous ,

please try below , please see below pbix for your reference

https://drive.google.com/file/d/1HVSc9j7yGE1vVXxvZBNf2HpFaeQrTi4z/view?usp=drive_link

 

Trending Headcount =
CALCULATE(
    COUNTROWS(employee),FILTER(ALLEXCEPT(employee,employee[endofmonthemp]),
    employee[eff_tmstp]<=max(employee[endofmonthemp]) && employee[emp_status]="active"))
 
powerbiexpert22_0-1735829966942.png

 

Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.  Show the expected result clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Anonymous ,

Based on the description, try using the following DAX formula.

Trending Headcount = 
VAR MaxDate = MAX('Date'[EndOfMonth])
RETURN
CALCULATE(
    DISTINCTCOUNT(Emp[EMP_ID]),
    FILTER(
        Emp,
        Emp[EFF_TMSTP] <= MaxDate &&
        (
            Emp[EMP_STATUS] = "Active" ||
            (
                Emp[EMP_STATUS] = "Terminated" &&
                Emp[EFF_TMSTP] > MaxDate
            )
        )
    )
)

 

Best Regards,

Wisdom Wu

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

Anonymous
Not applicable

Hi @Anonymous , 

Thanks for taking a stab at this challenge, used your DAX measure and didn't quite turn out what I was looking for, if you could see in the snapshot below. 

 

Great that it counts the EMP_ID once per month, like on 07/2023, the employee had multiple records all of which were active and so counting them once for the month is exactly the desired outcome. Not so great, in the highlighted parts of the middle table we can see the employee was active in 05/31/2023, 09/30/2023, and 11/30/2023, but on the output table on the right, it's not shown. Playing with the measure now and trying to figure this out, any help would be greatly appreciated, also uploading the data so it can be copied into excel as a previous user requested. Thanks again. 

 

snippet1.png

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.