Forum Discussion

chasuk19's avatar
chasuk19
Frequent Visitor
4 years ago
Solved

Hourly Duration Chart Help

Hi all, i'm struggling with some data, in which I need to SUM the duration of a list of tasks and spread this duration on a graph/line chart across an hourly basis.

 

My data set shows the task, it's start and end time and duration. (i also have date, but filtered out for this).

 

Task  End TimeDurationStart Day
Task 123:45:0002:45:00Monday
Task 123:55:0002:35:00Monday
Task 218:00:0001:15:00Tuesday

 

 

 

I'm trying to sum the time spent across each task per hour (in mins) and display it simarly to below. 

 

Can anyone help please? (apologies if asked before, but i couldnt find anything relevant).

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi chasuk19 ,

     

    You may try to create a Hours Table first and use CROSSJOIN() to merge two tables.

     

    1.Hours Table

    Hours = GENERATESERIES(1,24,1)

    2. Merge tables:

    New Table = 
    FILTER (
        CROSSJOIN ( 'Table', 'Hours'),
        HOUR ('Table'[Start Time] ) <= 'Hours'[Hour of Day]
            && HOUR ('Table'[End Time] ) >= 'Hours'[Hour of Day]
    )

    3.Calculate the duration of each Hour:

    duration in hour = 
    IF (
        HOUR ( 'New Table'[Start Time] ) = HOUR ('New Table'[End Time] ),
        MINUTE ('New Table'[End Time] ) - MINUTE ('New Table'[Start Time] ),
        IF (
            HOUR (  'New Table'[Start Time] ) ='New Table'[Hour of Day],
            60 - MINUTE (  'New Table'[Start Time] ),
            IF ( HOUR ( 'New Table'[End Time] ) = 'New Table'[Hour of Day], MINUTE ( 'New Table'[End Time]), 60 )
        )
    )

    Below is the final output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • chasuk19's avatar
    chasuk19
    Frequent Visitor

    After thinking about this more, I think the best way to achieve this is to 'split' out my data into a calculated table and represent the duration as minutes across each hour from each task, like the below. How would I be able to possibly achieve these?

     

     

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi chasuk19 ,

     

    You may try to create a Hours Table first and use CROSSJOIN() to merge two tables.

     

    1.Hours Table

    Hours = GENERATESERIES(1,24,1)

    2. Merge tables:

    New Table = 
    FILTER (
        CROSSJOIN ( 'Table', 'Hours'),
        HOUR ('Table'[Start Time] ) <= 'Hours'[Hour of Day]
            && HOUR ('Table'[End Time] ) >= 'Hours'[Hour of Day]
    )

    3.Calculate the duration of each Hour:

    duration in hour = 
    IF (
        HOUR ( 'New Table'[Start Time] ) = HOUR ('New Table'[End Time] ),
        MINUTE ('New Table'[End Time] ) - MINUTE ('New Table'[Start Time] ),
        IF (
            HOUR (  'New Table'[Start Time] ) ='New Table'[Hour of Day],
            60 - MINUTE (  'New Table'[Start Time] ),
            IF ( HOUR ( 'New Table'[End Time] ) = 'New Table'[Hour of Day], MINUTE ( 'New Table'[End Time]), 60 )
        )
    )

    Below is the final output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.