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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nishik
New Member

Count of employees on leave based on start and end date range

I would like to get a count of employees on leave for each day of the year.  I have a calendar table as well as a table with the following fields:

-Employee

-Leave From Date

-Leave To Date

-Leave in hours

 

For example, if employee#1 was on leave from 2018-01-08 until 2018-01-12 and employee #2  was on leave from 2017-01-11 until 2018-01-12 then I would like to return the following data:

Date                    Employees on Leave

2018-01-08                    1

2018-01-09                    1

2018-01-10                    1

2018-01-11                    2

2018-01-12                    2

1 ACCEPTED SOLUTION
WolfBiber
Microsoft Employee
Microsoft Employee

Hey,

I made a fast pbix of your data.

Find it under this link:

https://1drv.ms/u/s!AuNGof2uT8Pphf1ZoYRQWh9C0Lz3aQ

 

Unbenannt.png

Its in german, but I think the point is understandable 😄

 

Greetings.

View solution in original post

5 REPLIES 5
WolfBiber
Microsoft Employee
Microsoft Employee

ok, but what is the problem about?

I would like to get a count of employees on leave for each day of the year that the leave range spans.

 

I have a calendar table as well as a table with the following fields:

-Employee

-Leave From Date

-Leave To Date

-Leave in hours

 

For example, if employee#1 was on leave from 2018-01-08 until 2018-01-12 and employee #2  was on leave from 2018-01-11 until 2018-01-12 then I would like to return the following data:

Date                    Employees on Leave

2018-01-08                    1

2018-01-09                    1

2018-01-10                    1

2018-01-11                    2

2018-01-12                    2

 

Currently, the calendar date is linked to the "Leave from Date".  The "Employees on Leave" count I currently see is only counting the day that the employee starts their leave ("Leave from Date") and does not count the employee on leave each day until it reaches the "Leave to Date".  So I see:

Date                    Employees on Leave

2018-01-08                    1

2018-01-11                    1

 

WolfBiber
Microsoft Employee
Microsoft Employee

hey,

refer starting point here : https://blog.gbrueckl.at/2014/12/events-in-progress-for-time-periods-in-dax/

You need a date table with no relations to other tabels in your model. 

Then try something like

On Leave =
 CALCULATE(
  COUNTROWS(EmployeeID);
   FILTER( 'EmployeeLeave'; 'EmployeeLeave'[Leave From Date] <= MAX(NewDateTable[Date]));
   FILTER( 'EmployeeLeave'; 'EmployeeLeave'[Leave To Date] = BLANK() || 'EmployeeLeave'[Leave To Date] > MAX( NewdateTable[Date]))
      
   ) 

Using the above measure I was unable to get the correct count of employees On Leave.  Here is an example of some the data:

EmplIDFrom DateTo Date
12017-12-222018-01-03
22017-12-272018-01-03
32018-01-022018-01-05
42018-01-022018-01-05
52018-01-022018-01-02
62018-01-022018-01-03
72018-01-022018-01-02
82018-01-022018-01-03
92018-01-022018-01-05
102018-01-042018-01-04
112018-01-052018-01-05
122018-01-052018-01-05

 

This is the result I am seeing (ie. 2018-01-02 should have a count of 9 not 7):

DateOn Leave
2017-12-221
2017-12-231
2017-12-241
2017-12-251
2017-12-261
2017-12-272
2017-12-282
2017-12-292
2017-12-302
2017-12-312
2018-01-012
2018-01-027
2018-01-033
2018-01-043
2018-01-051
2018-01-061
2018-01-071
2018-01-081
2018-01-091

 

It would also be great if I could remove weekends and holidays from the table.

WolfBiber
Microsoft Employee
Microsoft Employee

Hey,

I made a fast pbix of your data.

Find it under this link:

https://1drv.ms/u/s!AuNGof2uT8Pphf1ZoYRQWh9C0Lz3aQ

 

Unbenannt.png

Its in german, but I think the point is understandable 😄

 

Greetings.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.