Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DarrelDonatto
Frequent Visitor

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.

 

2 ACCEPTED SOLUTIONS
v-chenwuz-msft
Community Support
Community Support

Hi @DarrelDonatto ,

 

Is this you want?

vchenwuzmsft_0-1656568055598.png

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.

View solution in original post

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?

View solution in original post

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @DarrelDonatto ,

 

Is this you want?

vchenwuzmsft_0-1656568055598.png

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.

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?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.