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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
ChrisPBIUser
Helper III
Helper III

Employee Headcount : By Department each month

Hi, really stuck on this one.  I have the following DAX formula which works fine if I want the number of active employees for each month. 

Employee Count1 =
CALCULATE( DISTINCTCOUNT( 'Fact_HRData'[Employee Id]),
ALLSELECTED( 'Fact_HRData'[Employee Id] ),
FILTER( VALUES( 'Fact_HRData'[Start Date] ), 'Fact_HRData'[Start Date] <= MAX( 'Date'[Date] ) ),
FILTER( VALUES( 'Fact_HRData'[Leaving Date] ), OR( 'Fact_HRData'[Leaving Date] >= MIN( 'Date'[Date] ), ISBLANK( 'Fact_HRData'[Leaving Date] ) ) ) )
 
So :
Image2.JPG
 
I have two tables, Date and Fact_HRData with two inactive relationships :

Date[Date] > Fact_HRData[Start Date]

Date[Date] > Fact_HRData[Leaving Date]

 

Image1.JPG

 

However, what I need is a breakdown for each month by department.  At the moment I just get this

Image3.JPG

 

What I want is the DAX formula to split out the totals for each month by the relevant department.  Slicers for the department give me the same result so I suspect it somethings within my original DAX formula but can't figure out what it is.

Any help will be appreciated

 

4 REPLIES 4
Anonymous
Not applicable

The OR function takes only 2 arguments. You've got 3 in there.

There are only 2 in my DAX statement and that DAX works.  I just need it expanding to split by Department.  The OR in the 1st response has 3 arguments which has already been pointed out to the poster.

jameszhang0805
Resolver IV
Resolver IV

Please active relationship for Date[Date] > Fact_HRData[Start Date] then try below code 
CALCULATE (
    DISTINCTCOUNT ( 'Fact_HRData'[Employee Id] ),
    ALLSELECTED ( 'Fact_HRData'[Employee Id] ),
    FILTER (
        VALUES ( 'Fact_HRData'[Start Date] ),
        'Fact_HRData'[Start Date] <= MAX ( 'Date'[Date] )
    ),
    FILTER (
        VALUES ( 'Fact_HRData'[Leaving Date] ),
        OR (
            'Fact_HRData'[Leaving Date] >= MIN ( 'Date'[Date] ),
            ISBLANK ( 'Fact_HRData'[Leaving Date] ),
            USERELATIONSHIP('Fact_HRData'[Leaving Date] , 'Date'[Date] )
        )
    )
)

Cheers for the quick response but I get errors with this DAX formula as per below :

Image4.JPG

If I remove the comma I then get this error :

Image5.JPG

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.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.