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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
smanderson
Frequent Visitor

Number of rows between a start and end date

I'm starting with a Data Source Structured like this:

 

smanderson_0-1622673923733.png

 

I intend to produce a table/viz showing how many employees were employed on any given date by department like this:

 

smanderson_1-1622673972973.png

 

I've explored some other help topics and it seems like this invovles filter context and related tables, but I'm not sure how to crack it. Thanks in advance!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @smanderson 

Please check the below picture and the sample pbix file's link down below.

 

All measures are in the sample pbix file.

 

Picture1.png

 

Apple employees =
CALCULATE (
COUNTROWS ( employees ),
employees[department] = "apple",
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR(employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
Banana employees =
CALCULATE (
COUNTROWS ( employees ),
employees[department] = "banana",
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR( employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
Total employees =
CALCULATE (
COUNTROWS ( employees ),
 
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR(employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @smanderson 

Please check the below picture and the sample pbix file's link down below.

 

All measures are in the sample pbix file.

 

Picture1.png

 

Apple employees =
CALCULATE (
COUNTROWS ( employees ),
employees[department] = "apple",
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR(employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
Banana employees =
CALCULATE (
COUNTROWS ( employees ),
employees[department] = "banana",
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR( employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
Total employees =
CALCULATE (
COUNTROWS ( employees ),
 
FILTER (
employees,
employees[Hire Date] <= MAX ( Dates[Date] )
&& OR(employees[Fire Date] >= MIN ( Dates[Date] ), ISBLANK(employees[Fire Date]))
)
)
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@smanderson , usually we do it with help from date table as discussed in my blog

 

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

 

create a separate date and department table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Great Blog post!  I must be doing something wrong, The "current employees" measure seemed to get stuck on the first day's total for me.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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