Forum Discussion

Jbrunson09's avatar
Jbrunson09
Frequent Visitor
4 years ago
Solved

Value spread across dates and time based on calendar assignment table

Hello,   Pre warning is that I'm newer to DAX so my terminology might not be correct. But any help on solving my issue would be greatly appreicated as I couldnt find anything in previous posts.   ...
  • lbendlin's avatar
    4 years ago

    Kudos for taking on such a rather complex topic.  You're on the right track but you may want to clean up a bit. Too many dangly bits, too many extra visuals etc.

     

    All you need to start is the Activities table and the (disconnected) Dates table.  Then you can process each interval the way you did it - Beginning day, intermediate days, ending day.  There are a lot of caveats here that we are going to ignore  (for example work starting on a weekend day or starting on a workday at 12pm, beginning and ending on the same day, exact weekend days etc)

    Hour_Count_PD = 
    switch(TRUE(),
    -- beginning and ending on the same day
    max(ACTIVITIES[Start_date_key])=max(ACTIVITIES[Finish_date_key]),DATEDIFF(min(ACTIVITIES[Start_time_key]),min(ACTIVITIES[Finish_time_key]),HOUR)-if(min(ACTIVITIES[Start_time_key])<time(12,0,0),1,0),
    -- starting day hours
    SELECTEDVALUE(DATES[Date])=max(ACTIVITIES[Start_date_key]),DATEDIFF(min(ACTIVITIES[Start_time_key]),TIME(17,0,0),HOUR)-if(min(ACTIVITIES[Start_time_key])<time(12,0,0),1,0),
    -- ending day hours
    SELECTEDVALUE(DATES[Date])=max(ACTIVITIES[Finish_date_key]),DATEDIFF(TIME(8,0,0),min(ACTIVITIES[Finish_time_key]),HOUR)-if(min(ACTIVITIES[Finish_time_key])>time(12,0,0),1,0),
    -- in between days
    SELECTEDVALUE(DATES[Date])>max(ACTIVITIES[Start_date_key]) && SELECTEDVALUE(DATES[Date])<max(ACTIVITIES[Finish_date_key]) && SELECTEDVALUE(DATES[Day of Week]) in {1,2,3,4,5},8)

    see attached