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
Anonymous
Not applicable

Calculation of measure on the fly per day count of sick staff

Hi,

 

I will be so thankful if someone can assist writing smart DAX for the below scenario. I hope this will be a quick DAX coding for someone.

 

I have a table with 4 columns 

Assignment numberDepartmentSickness Start DateSickness End Date
1IT04/04/202002/04/2020
2HR01/04/2020 
3Finance01/03/202005/04/2020
4Finance15/03/202006/04/2020
5HR10/02/2020 
6HR01/01/2020 
7IT02/01/202001/04/2020
8Nursing03/01/202002/04/2020
9IT04/01/2020 
10Nursing05/01/2020 
11Nursing06/01/202007/04/2020
12Nursing07/01/202006/04/2020
13Nursing08/01/202006/04/2020
14Nursing09/01/2020 

 

I want to find out how many staff members were off sick on each day of April 2020 till 9th April. Answer will be like

 

Month dayOff sick HR Off sickIT Off sickNursing Off sickFinance Off sick
01 Apr 2020143362
02 Apr 2020133262
03 Apr 2020113152
04 Apr 2020113152
05 Apr 2020113152
06 Apr 2020103151
07 Apr 202073130
08 Apr 202063120
09 Apr 202063120

 

I do not have table to keep each day of month separately but can create a DimDate but how to create a link between these two tables as it seems there is a complex linkage. 

 

If someone copy this dataset in PBIX and share will be ideal. 

 

Formula to calculate each day is, for example if you are check off sick on 4th April  = All staff with Sick end date as blank or null and also those whose sick end date is on or after 5th April.

 

Please suggest how I can achieve this. 

 

Many thanks

 

2 ACCEPTED SOLUTIONS
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

I've create this file as an example: Download PBIX 

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

Hi @Anonymous ,

 

I just changed the code for D_Date table, creating the date with Apr 9th - 30.

 

Download PBIX 

 

I hope it works.

 

If this is a solution, please mark as a solution and kudos.

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

I've create this file as an example: Download PBIX 

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Hi @camargos88

 

This is outstanding. Thanks a lot for such a prompt and perfect solution.

 

One last things, 

What if I do not want a slicer(date selected 01Apr-09Apr) and just want to bring last 30 days automatically instead of leaving users with slicer? Last 30 days from max date which is 09 Apr?

 

Already so helpful but if you can provide this, that will be great. 

Your solution has given me a new direction in DAX scripting.

 

* correction in data: Off sick for 01Apr is 13 not 14 and @camargos88  solution has automatically fixed it, in case if someone use this example in future. 

 

Many thanks

 

Hi @Anonymous ,

 

I just changed the code for D_Date table, creating the date with Apr 9th - 30.

 

Download PBIX 

 

I hope it works.

 

If this is a solution, please mark as a solution and kudos.

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Awesome!!

 

I changed Date table as 

For last 30 days from today 's date

D_Date2 = CALENDAR(TODAY()-30, TODAY())
 
For last 30 days from maximum sickness end date.
D_Date1 = CALENDAR(MAX('Table'[Sickness End Date])-30, IF(Max('Table'[Sickness End Date].[Date])=BLANK(),TODAY(),MAX('Table'[Sickness End Date])))
 

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