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
TapZxK
Helper II
Helper II

Count by Date Range - Looking for Help

Hi Everyone, 

 

I have encountered yet another problem that I'm looking to solve. 

 

I have a table with employee names that also contain their start-dates and roll-off dates.

Example:

 

Name // Start Date // Roll-Off Date 

Kris // 01-Sep-2018 // 12-Dec-2020

Alice // 01-Jun-2019 // 01-Oct-2019

Mark // 17-Jan-2018 // 10-Aug-2018

Karen // 03-May-2019 // 17-Oct-2018

Lisa // 27-Mar-2019 // 11-Sep-2020

 

 

What I'm looking for is a measure that will count the rows and return an "Active" Headcount, based on the data range.

 

For example, I want to know how many "Active" employees we have in October 2019. Measure then looks at the start date & end date of the employee and only returns Active head count number for people who's roll-off date is not in the past. For example using the table above, the total active headcount returned should be = 2, since only Kris and Lisa have Roll-off dates in the future. 

I then would like to create a slicer so I can go back to other month's and see how many Active people I had in May or June, or September and so on.

 

I'm fairly new to Power BI and I'm learning a lot. but this is something I can't yet figure out how to do. 

Your help is much appreciated. 

 

Best Regards,

Kris

1 ACCEPTED SOLUTION

 

Measure =
VAR CutOffDate_ =
    MAX ( CalendarTable[Date] )
RETURN
    COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_  || ISBLANK( Table1[Roll-Off Date] ) ) )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

View solution in original post

3 REPLIES 3
AlB
Super User
Super User

Hi @TapZxK 

1. Create a standard calendar table (no relationships to the table you show). Place month and year in a slicer.

2.  Place this measure in a card visual (assumes only one row per employee in the table you show (Table1))

Measure =
VAR CutOffDate_ =
    MAX ( CalendarTable[Date] )
RETURN
    COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_ ) )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

    

Hi @AlB ,

 

Thanks for the Suggestion. 

I already had a rolling-calendar created, There is no relationship between the Employe Table and calendar. 

 

 

What if the Roll-off date contains a lot of "Null" values as the people who are not yet rolled-off will not have the date in there. 

is it possible to amend the formula so that it also counts the null values too please?

 

BR,

Kris

 

Measure =
VAR CutOffDate_ =
    MAX ( CalendarTable[Date] )
RETURN
    COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_  || ISBLANK( Table1[Roll-Off Date] ) ) )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

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.