Forum Discussion

andrezmor's avatar
andrezmor
Frequent Visitor
5 years ago
Solved

Summarize According to selected time Interval

Hi there.  I am having some trouble finding a solution to the next problem. I appreciate your help and suggestions.   I have an Event Table with 3 columns as the following   I want to be able to ...
  • MFelix's avatar
    5 years ago

    Hi andrezmor ,

     

    First of all believe that you are counting 12 additional hours on the Class C according to your data the C values are has accordingly:

    Start Time

        End Time

       Event Class

    6/3/2021 2:30

       6/3/2021 14:30

       Class C

    5/21/2021 20:00

       5/22/2021 4:15

       Class C

    3/5/2021 13:00

       3/6/2021 13:00

       Class C

     

    If your filter is based on the 3/5 and 3/7 only the third line is consider makingi it the 24 hours and not 36, I assume you are counting also the first 12 hours from the first line but it does not match the filter.

     

    Try the following measure:

    Total Hours = 
    VAR temp_table =
        FILTER (
            SUMMARIZE (
                ALL ( 'Table'[Event Class], 'Table'[Start Time], 'Table'[End Time] ),
                'Table'[Event Class],
                'Table'[Start Time],
                'Table'[End Time],
                "@HourDifference",
                    DATEDIFF (
                        MAX ( 'Table'[Start Time], MIN ( 'Calendar'[Date] ) ),
                        MIN ( 'Table'[End Time], MAX ( 'Calendar'[Date] ) ),
                        HOUR
                    )
            ),
            [@HourDifference] > 0
                && 'Table'[Event Class] IN VALUES ( 'Table'[Event Class] )
        )
    RETURN
        COALESCE ( SUMX ( temp_table, [@HourDifference] ), 0 )