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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
joshcomputer1
Helper V
Helper V

Calculating a monthly employee count from a start and end date range

Hi there, 

I just need some help organizing how to do this.  I have a table that displays the employees' names, title, start date, end date and "active?".  The active column just shows whether they are an active employee today or not.  

 

What I am wanting is to be able to show (based on the start date and end date columns how many employees we had for each month.  The range right now only goes back to Jan. 1, but want to get started on this. Any help is appreciated.

 

**I thought about just having a column for each month with a 1 or 0 if they were active during the month.  This would work, except there is additional columns added for each month and this is not maintenance free (at least not how I had it).  I am familiar with excel but new to power BI. 

 

table= tblEmployees

column= EmpName

column= colStartDate

column= colEndDate

column= colActive?

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @joshcomputer1,

 

If I understand you correctly, you should be able to follow steps below to get the monthly employee count from a start and end date range.

 

1. Add an individual Calendar table if you don't have one yet.

Date = CALENDARAUTO()

2. Use the formula below to create a measure, and show the measure on the Chart visual with Date[Date] column as Axis.

Count of Active Employee =
VAR currentDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            ( Table1[Start Date] <= currentDate
                && Table1[End Date] >= currentDate )
                && Table1[Active?] = 1
        )
    )

r4.PNG

Here is the sample pbix file for your reference. Smiley Happy

 

Regards

View solution in original post

24 REPLIES 24
GilbertQ
Super User
Super User

Hi @joshcomputer1

 

Do you have some sample data, which will make it easier?

 

You could so a measure with the following syntax below, but you would require to have a Date Table in order for this to work. Where you create a relationship your data to the Date table.

 

radacad.com/do-you-need-a-date-dimension

 

Total Employees = 
VAR EarliestDate = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED()) 
RETURN CALCULATE(DISTINCTCOUNT('tblEmployees'[colActive]),FILTER(ALL('Calendar'[Date]),'Calendar'[Date] <= MAX('Calendar'[Date]) && 'Calendar'[Date] >= EarliestDate))

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

How do I add a relationship to the date calendar? Relate the start and end dates columns to it? I already have months and years and week numbers columns in most of my excel docs and would like to move away from that.

Hi @joshcomputer1,

 

The relationship to the date calendar is not needed here.

 

Could you share a sample pbix file, so that we can better assist on this issue? You can upload it to OneDrive or Dropbox and post the link here, or sent it to me in private message. Do mask sensitive data before uploading. Smiley Happy

 

Regards

TeamNameGMSMRoleStart DateEnd DateActive?
FirstMichael KayesBobIT Support Agent3/30/20165/25/20171
FirstEnrique KayesBobIT Support Agent12/23/20155/25/20171
FirstJerryKayesBobIT Support Agent10/21/20135/25/20171
FirstJimKayesBobSM7/1/20125/25/20171
        

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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