Forum Discussion

rogletree's avatar
rogletree
Icon for Helper III rankHelper III
5 years ago
Solved

DAX experts, I need help with time manipulation

I have a table that tracks downtimes for machines. Some fields I have are [start_time] & [end_time] (both are datetime), [duration] (in minutes as a decimal number). Those are all pretty self-explana...
  • AlB's avatar
    AlB
    5 years ago

    rogletree 

    1. You need a complete date-time table with all the hours, no gaps. You should also have a full date table with all days in the year (full years) to avoid unexpected issues.

    2. No relationship between date-time table and Main table 

    3. Create this measure for the chart:

     

    Measure = 
    VAR startSlot_ = SELECTEDVALUE('date hours'[date_hour])
    VAR endSlot_ = startSlot_ + (1/24) //1 hour later
    RETURN
    SUMX(Main, 
    VAR aux_ =  MIN(endSlot_,Main[end_time])- MAX(startSlot_, Main[start_time])
    VAR timeInSlot_ = IF(aux_>=0, 24*60*aux_, 0)
    RETURN
    timeInSlot_)

     

    4. See it all at play in the attached file

     

     

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers