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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
fraitaan
Frequent Visitor

Calculate sick headcount

Hi, 

I've been searching around for a while and I've found a few formulas that somewhat works but doesn't go all the way. 

I'm using this formula to calculate headcount at our company, and it works well: 

 

 

Headcount = CALCULATE(
     'Calculations'[Count of Employees]
     , FILTER(
         Merge1
         , (
             Merge1[Date of Hire] <= MAX(DimDate[Date])
          && Merge1[Date of Termination] > MAX(DimDate[Date])
          ) || ISBLANK(Merge1[Date of Termination])
     ))

 

 

 
Now I need to calculate how many people that were sick each day but i don't know how to "take away" the work-able employees. 

 

 

Test sick people = CALCULATE(
     'Calculations'[Count of Employees]
     , FILTER(
         Merge1
         , (
             Merge1[Sick from] <= MAX(DimDate[Date])
          && Merge1[Sick too] > MAX(DimDate[Date])
          ) || ISBLANK(Merge1[´Sick too])
     ))

 

 

This is the result: 

fraitaan_0-1673946438608.png


The data could looks like this: 

EmployeeSick fromSick too
ID-12022-11-102022-11-13
ID-22022-11-012022-11-05
ID-22022-11-102022-11-15
ID-3nullnull

 

Hope I made it understandable. 

If all employees are work-able/healthy, then the table should show nothing/blank and if someone is sick, it should be visible how many people, totally, are sick everyday. So in above example data it would be: 
                     
                       Sick people
2022-11-01: 1
2022-11-02: 1

2022-11-03: 1

2022-11-04: 1

2022-11-05: 1

2022-11-06:  (blank)/0

2022-11-07:  (blank)/0

2022-11-08:  (blank)/0

2022-11-09:  (blank)/0

2022-11-10: 2

2022-11-11: 2

2022-11-12: 2

2022-11-13: 2

2022-11-14: 1

2022-11-15: 1

2022-11-16:  (blank)/0

Thanks!

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @fraitaan ,

 

According to your description, you want to calculate the count of the sick people according to every date.

Here are the steps you can refer to :

(1)My test date is the same as yours.

 

(2)We can create a date table as a dimension table, and we do not need to create a relationship between two tables.

Date = CALENDAR( DATE(2022,11,1) ,DATE(2022,11,16))

 

(3)Then we can create a measure:

Measure = var _cur_date = MAX('Date'[Date])

var _t = FILTER( 'Table' , 'Table'[Sick from]<=_cur_date && 'Table'[Sick too]>= _cur_date)

return

COUNTROWS(_t)+0

 

(4)Then we can put the fields we need on the visual and we can meet your need , the result is as follows:

vtangjiemsft_0-1674033282616.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

3 REPLIES 3
v-tangjie-msft
Community Support
Community Support

Hi @fraitaan ,

 

According to your description, you want to calculate the count of the sick people according to every date.

Here are the steps you can refer to :

(1)My test date is the same as yours.

 

(2)We can create a date table as a dimension table, and we do not need to create a relationship between two tables.

Date = CALENDAR( DATE(2022,11,1) ,DATE(2022,11,16))

 

(3)Then we can create a measure:

Measure = var _cur_date = MAX('Date'[Date])

var _t = FILTER( 'Table' , 'Table'[Sick from]<=_cur_date && 'Table'[Sick too]>= _cur_date)

return

COUNTROWS(_t)+0

 

(4)Then we can put the fields we need on the visual and we can meet your need , the result is as follows:

vtangjiemsft_0-1674033282616.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

amitchandak
Super User
Super User

@fraitaan , Try like

 

Test sick people = CALCULATE(
'Calculations'[Count of Employees]
, FILTER(
Merge1
, (
Merge1[Sick from] <= MAX(DimDate[Date])
&& ( Merge1[Sick too] > MAX(DimDate[Date])
|| ISBLANK(Merge1[´Sick too]) ) && not(isblank(Merge1[Sick from]))
)) )

 

 

Power BI HR Active Employee Tenure Bucketing, and Hired, Terminated, and Active employees: https://youtu.be/fvgcx8QLqZU

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak , 

Thanks for fast answer! 

Now the healthy people have been removed but the count of sick people is wrong. 

According to my raw data, 116 people were sick on first of november (tuesday) 2022. But now it only shows 95 people. 

fraitaan_0-1673949832779.png


My count formula look like this: 

Count of employees = count(Merge1[ID])
Used count and not distinct count, because same person can be sick multiple times. 

Also realised that when a person is sick 1 day, the from and too date is the same.

EmployeeSick fromSick too
ID-22022-11-022022-11-02

Because the data is exported afterwards. 

I saw that 21 people were sick only one day (2022-11-01 -> 2022-11-01) and that is the explanation to why we only see 95 in the above picture. 

95 + 21 = 116

Got any other ideas?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.