Forum Discussion

DummyBIDev's avatar
DummyBIDev
Frequent Visitor
3 years ago

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

    • DummyBIDev's avatar
      DummyBIDev
      Frequent Visitor

      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

      • barritown's avatar
        barritown
        Icon for Solution Sage rankSolution Sage

        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] ) )

         

  • DummyBIDev's avatar
    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

    • barritown's avatar
      barritown
      Icon for Solution Sage rankSolution Sage

      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.

       

      • DummyBIDev's avatar
        DummyBIDev
        Frequent Visitor

        see screenshot of my visual

         

         

         

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