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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors