Forum Discussion

DarrelDonatto's avatar
DarrelDonatto
Frequent Visitor
4 years ago
Solved

Calculating the Date/Time difference between two rows (not always consecutive)

I have a table where date/time values are stored within rows by Incident # and Unit.

 

I am trying to calculate the difference between these values in any given row for an incident number and unit.  Note, the date/times in rows are not always consecutive.

 

Here is a sample of the table:

Data Table        
calltimeclosecodeunitcodeparent_idusertypedtimeinsecstimestampdescripttranstype
6/1/2022  7:14:42 PM BC972022152110[Unit Recommendation]69,3076/1/2022  7:15:07 PMDispatchedD
6/1/2022  7:14:42 PM E982022152110[Unit Recommendation]69,3076/1/2022  7:15:07 PMDispatchedD
6/1/2022  7:14:42 PM R982022152110[Unit Recommendation]69,3076/1/2022  7:15:07 PMDispatchedD
6/1/2022  7:14:42 PM R982022152110Entered in Event History - Log Entry.69,3646/1/2022  7:16:04 PMEn-RouteE
6/1/2022  7:14:42 PM E982022152110Mobile Computer Change69,3716/1/2022  7:16:11 PMEn-RouteE
6/1/2022  7:14:42 PM BC972022152110[Enroute Button]69,3846/1/2022  7:16:24 PMEn-RouteE
6/1/2022  7:14:42 PM R982022152110[Arrive Button]69,4636/1/2022  7:17:43 PMArrivedA
6/1/2022  7:14:42 PM E982022152110[Arrive Button]69,4646/1/2022  7:17:44 PMArrivedA
6/1/2022  7:14:42 PM BC972022152110Mobile Computer Change69,5996/1/2022  7:19:59 PMArrivedA
6/1/2022  7:14:42 PM R982022152110R98 T69,7486/1/2022  7:22:28 PMTransportT
6/1/2022  7:14:42 PM R982022152110R98 T69,7486/1/2022  7:22:28 PMBeg MileageMILE
6/1/2022  7:14:42 PMBUPBC972022152110BC97 E98 C BUP70,0746/1/2022  7:27:54 PMClearedC
6/1/2022  7:14:42 PMBUPE982022152110BC97 E98 C BUP70,0746/1/2022  7:27:54 PMClearedC
6/1/2022  7:14:42 PM R982022152110R98  H70,1206/1/2022  7:28:40 PMAt HospitalH
6/1/2022  7:14:42 PM R982022152110R98  H70,1206/1/2022  7:28:40 PMEnd MileageMILE
6/1/2022  7:14:42 PMFIRR982022152110R98 C FIR71,8926/1/2022  7:58:12 PMClearedC

 

 

Here is the desired result:

Desired Result    
parent_idunitcodeDispatchedEn-RouteTurnout Time
2022152110E986/1/2022  7:15:07 PM6/1/2022  7:16:11 PM01:04

 

I would appreciate any guidance.

 

  • Hi DarrelDonatto ,

     

    Is this you want?

    You can use matrix table visual to do this with a measure like the following:

    Turnout Time =
    VAR _dis =
        CALCULATE (
            MAX ( 'DateTable'[timestamp] ),
            FILTER ( 'DateTable', [descript] = "dispatched" )
        )
    VAR _enr =
        CALCULATE (
            MAX ( 'DateTable'[timestamp] ),
            FILTER ( 'DateTable', [descript] = "en-route" )
        )
    RETURN
        IF (
            HASONEVALUE ( DateTable[descript] ),
            FORMAT ( MAX ( 'DateTable'[timestamp] ), "mm/dd/yyyy hh:nn:ss AMPM" ),
            FORMAT ( _dis - _enr, "h:mm:ss" )
        )
    

     

     

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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

  • DarrelDonatto's avatar
    DarrelDonatto
    4 years ago

    This is great.  Thanks so much.  It solves much of what I am trying to accomplish.  Is there a way to get the same measure not in matrix visualization, but so I can use the result to calculate a 90th percentile or an average per unit?

2 Replies

  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    Community Support

    Hi DarrelDonatto ,

     

    Is this you want?

    You can use matrix table visual to do this with a measure like the following:

    Turnout Time =
    VAR _dis =
        CALCULATE (
            MAX ( 'DateTable'[timestamp] ),
            FILTER ( 'DateTable', [descript] = "dispatched" )
        )
    VAR _enr =
        CALCULATE (
            MAX ( 'DateTable'[timestamp] ),
            FILTER ( 'DateTable', [descript] = "en-route" )
        )
    RETURN
        IF (
            HASONEVALUE ( DateTable[descript] ),
            FORMAT ( MAX ( 'DateTable'[timestamp] ), "mm/dd/yyyy hh:nn:ss AMPM" ),
            FORMAT ( _dis - _enr, "h:mm:ss" )
        )
    

     

     

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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

    • DarrelDonatto's avatar
      DarrelDonatto
      Frequent Visitor

      This is great.  Thanks so much.  It solves much of what I am trying to accomplish.  Is there a way to get the same measure not in matrix visualization, but so I can use the result to calculate a 90th percentile or an average per unit?