Forum Discussion

Roy1790's avatar
Roy1790
New Member
1 year ago
Solved

Create multiple measures to count alarms in various time buckets

SO i have a table with Alarm ID, Alarm_TImeSet, Alarm_TImeReset, AlarmName, StationName, SystemName.  Some alarms go into multiple time buckets, they start at 1200 am but continue till 1230 am, so t...
  • lbendlin's avatar
    lbendlin
    1 year ago
    Match =
    VAR b =  // starting second for the selected 15 minute bucket of the selected day
        ROUNDDOWN (
            ( MAX ( 'Time Buckets'[Column1] ) + MAX ( 'Calendar'[Date] ) ) * 86400,
            0
        )
    VAR b2 = // all seconds for the selected 15 minute bucket of the selected day
        GENERATESERIES ( b, b + 899 )
    VAR a =
        ADDCOLUMNS (
            'Table',
            "m",
                COUNTROWS (
                    INTERSECT (
                        b2, //  all seconds in the bucket
                        GENERATESERIES ( // all seconds in the alarm
                            ROUNDDOWN ( [Set] * 86400, 0 ),
                            ROUNDDOWN ( [Reset] * 86400 - 1, 0 )
                        )
                    )
                )
        )
    RETURN
        SUMX ( a, [m] ) // how many seconds in the bucket match the seconds in the alarm

     

    There's not really much to it. Datetime values can be divided into the Integer part (day) and the fraction part (time).  For easier calculation and to avoid rounding errors all values are multiplied by 86400 (the number of seconds in a day) which then results in simpler integer math.

     

    INTERSECT does most of the work by matching seconds between the two intervals.