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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

How to model data to show headcount by month

I am trying to set up an HR dashboard to show headcount by month. I have a Start Date and End Date for each employee, I also inserted a cond column showing if the employee is Active (1 if still with the company, 0 if he left), and a date table. I can't figure out what else I need to show that bar chart. I also believe that I need some date column (other than StartDate or End Date) to connect the main table to the date table.

 

Thanks for the help!

 

This is my sample dataThis is my sample data

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous

 

Try this:

 

1. Make sure your Date table includes all years in the data and every year in full. No relationship between 'Date' and your data table (Table1 in the code below)

2. Set 'Date'[Month] in the rows of a matrix visual (and 'Date'[Year] as well if required)

3. Create this measure and place it in values of the matrix: 

 

 

NumberActiveEmployees =
VAR _FirstDayCurrentMonth =
    MIN ( 'Date'[Date] )
VAR _LastDayCurrentMonth =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table1[Employee #] ),
        FILTER (
            Table1,
            Table1[Hire Date] <= _LastDayCurrentMonth
                && (
                    Table1[End Date] >= _FirstDayCurrentMonth
                        || ISBLANK ( Table1[End Date] )
                )
        )
    )

 

This will count as active everyone that was employeed at least one day in that month.

 

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. That allows people trying to help to readily copy the data and run some quick tests, plus it increases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous

 

Try this:

 

1. Make sure your Date table includes all years in the data and every year in full. No relationship between 'Date' and your data table (Table1 in the code below)

2. Set 'Date'[Month] in the rows of a matrix visual (and 'Date'[Year] as well if required)

3. Create this measure and place it in values of the matrix: 

 

 

NumberActiveEmployees =
VAR _FirstDayCurrentMonth =
    MIN ( 'Date'[Date] )
VAR _LastDayCurrentMonth =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table1[Employee #] ),
        FILTER (
            Table1,
            Table1[Hire Date] <= _LastDayCurrentMonth
                && (
                    Table1[End Date] >= _FirstDayCurrentMonth
                        || ISBLANK ( Table1[End Date] )
                )
        )
    )

 

This will count as active everyone that was employeed at least one day in that month.

 

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. That allows people trying to help to readily copy the data and run some quick tests, plus it increases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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