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
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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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

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
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.

Top Solution Authors