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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DummyBIDev
Frequent Visitor

Number of Days between two dates split by month - Employee Data

Hi All

 

Hoping you guys can direct me in the right direction, i've spent hours searching the forums and tried various suggesstions but nothing seems to work as i need it to. 

 

This post will be a bit detailed which hoping is a good thing

 

I have a set of tables

 

Date Table - This has a list of dates with the month, year, quarter, and a working day indicator

 

Sickness Table -This has a list of employee sicknesses - Employee ID, Sickness Start Date, Sickness End Date, Sick Reason

 

What i'd like to do

 

So the ask here is, i would like to create a measure that will show the number of sick days split by month. The data is currently like this 

 

Employee IDSick Start DateSick End Date
102/01/202310/01/2023
220/01/202304/02/2023
320/01/202310/02/2023
431/01/202308/03/2023

 

For the above data i would like it to be presented like this

 

MonthEmpSick Start DateSick End DateDays
January102/01/202310/01/20237 Days (This is to ex. holidays as per indicator in DATE table)
January431/01/202308/03/20231 Day (ONLY 1 day absent in the month of January)
February431/01/202308/03/202319 Days
February431/01/202308/03/20235 Days

 

 

So essentially i would like the number of days off to be split by month.

 

I have been trying to do this and i believe i was close. I have tried to relate the tables with DATE AND SICKNESS START DATE but when i relate them i am unable to get the split like above - if i do not relate the tables then i can get the split.

 

Another issue i was having is, i want to be able to sum up the total sick days to use it in a key metric visual

 

Hope that is enough detail, would appreicate any help

 

Thanks

11 REPLIES 11
DummyBIDev
Frequent Visitor

Thanks @barritown 

 

That measure works in a table, however the total of the measure doesn't add up correctly. How can i get the total to add up correctly? I.e. the total should show 48 but is showing as 21

@DummyBIDev,

Could you please clarify the problem for me with a screenshot or another PBIX file?

On my screenshot the total value is 48 so I don't get your point.

 

see screenshot of my visual

 

DummyBIDev_0-1699371870167.png

 

 

The number per sickness is correct, but the total at the bottom is incorrect

Don't you have some filter applied there or something else in the model I should be aware of? 

Any chance you can reproduce this problem with some mocking data and share PBIX?

 

P. S. It seems like your Total is showing the maximum value.

No filters applied on the table.

Just to be safe i created a whole new workbook and tried the filters but still the same issue

I've created a pbix file with dummy data which i'm hoping helps

Thanks

 

https://www.transfernow.net/dl/20231107VnVrATAN

barritown
Super User
Super User

Hi @DummyBIDev,

I guess you need something like the measure below in the model where your fact table is not related to your calendar table.

barritown_0-1699366842671.png

You can check how it works in the attached file.

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

I've downloaded the file but i can see your file has the same issue. The total figure of 48 is incorrect if you sum up all the individual values of the "Counter" column

@DummyBIDev,

Agree, my arithmetic skills are in decline. 😅

 

I can propose another measure on top of the earlier one:

Result = 
IF ( ISFILTERED ( 'Date'[Month] ),
     [Counter],
     VAR _tbl = ADDCOLUMNS ( CROSSJOIN ( VALUES ( 'Date'[Month] ), 'Data Table' ), "Temp", [Counter] )
     RETURN SUMX ( _tbl, [Temp] ) )

 

Hi Thanks for sending this. In isolation this works perfectly, however as soon as i add a slicer to the report and filter for one specific month it goes back to the counting the number of days in the calendar rather than sickness days.

Hi, yup, the solution was not universal. 

You filter months and what else?

So i've got a date hierarchy on the 'Month Ending' date in my date table. I use the month from this hierarchy to filter results

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.