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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.