Forum Discussion

electrobrit's avatar
electrobrit
Icon for Post Patron rankPost Patron
3 years ago
Solved

Capacity Hours by employee based on work week (work days with holidays)

Trying to get the capacity or available Hours (8 hours per day) by employee based on work week (work days with holidays) I have the work day and work hours in my calendar table my calendar table is...
  • sevenhills's avatar
    sevenhills
    3 years ago

    Hi

     

    a) I see you as post patron member. Hence, I was pointing things where it might be wrong and posted sample DAX table and values, so that it helps you to verify.
    It is not that I am saying it is wrong with your implementation.


    Data/Model 

    We need to fix things ... I tried like below, with my code from scratch:

     

    Calendar = 
     ADDCOLUMNS( 
         CALENDAR(DATE(2021,12,1),(DATE(2024,6,30)))
         , "Month Name", Format([Date], "mmmm")
         , "Month#", Month([Date])
         , "period start", [Date] - 6
         , "period end", [Date] - WEEKDAY([Date],2) + 6
         , "Quarter #", Format([Date], "q")
         , "Today", TODAY()
         , "WeekDay", FORMAT([Date], "dddd")
         , "Weekday#", WEEKDAY([Date])
         , "WeekNum", WEEKNUM([Date])
         , "Working Houors -Capacity By Day", IF (WEEKDAY([Date], 2 ) IN { 1, 2, 3, 4, 5 }, 8, 0 )
         , "Year", YEAR([Date])
     )

     

    Later added columns

     

    WorkingDay = If ( ISBLANK([Holiday]), If ([Weekday#] in {1 , 7}, 0, 1), 0)
    
    Working hours = CALCULATE(SUM([WorkingDay]) * 8)
    
    Period Working Hours = 
     var _PeriodEndDate = [period end] 
    return CALCULATE(count([Date]) * 8, filter(all('Calendar'), [period end] = _PeriodEndDate && ISBLANK([Holiday]) && [Weekday#] in {2, 3, 4, 5, 6}))

     

     

    The calendar table looks like this...

     

    now the below table looks good in my view:

     

    Table = SUMMARIZE( TimeDetail, TimeDetail[full_name], 'Calendar'[period end]
    , "Sum Test", Sum(TimeDetail[hours_worked])
    , "Sum Test Capacity", sum('Calendar'[Working Houors -Capacity By Day]) 
    , "Sum Period Hours", Sum('Calendar'[Period Working Hours])
    )

     

     

    Coming to visualization: it is looking good

    calendar period end, Period Working Hours, time details period_end_date

     

    Coming to your final output expected: 

    Note: I cannot match your output in the post above. This is due to the data you have holiday as on Sept 5 and expecting 40 hours. It should be 32 hours for that period due to holiday. 

     

     

     

    (You can rename the columns in the output visualization to your needs).

     

    b) Could you (re-)upload the pbix file with your changes? I will take a look

     

    You said "I changed the relationship but it didn't do anything. Data types are "dates"
    The working hours are correct by date, by Calendar period end and Time Detail period end date until you add the employee name and all the working hours change to 0."

     

    In my view, rollup is not happening with period end date but instead happening from date column in the calendar. This is due to period end date is mapped to date. 

    Thanks