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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
BDHicks
New Member

How to calculate duration across rows

Hi, all.

 

I'm new to Power BI and could use some advice on calculating duration across rows. Ideally, I'd add an additional column where the duration of an event would be calculated and stored with the "stop" event (Door Forced Open Canceled).

 

In a typical dataset, I have events occuring within the same second, so they often appear out-of-order if sorted by time. I could likely solve this as the SQL timestamps have ms resolution, but I haven't figured out an efficient way to access the ms value within PBI. So my other option is to utilize other data that can be used to determine the proper sequence, as each event is associated with a specific device (Panel ID), which maintains its own internal serialization data (Panel Index).

 

I'm typically dealing with datasets that run from 2-60 million rows, so at the end of the day, I'm looking for the most efficient method for calculating the duration between the start and stop events. A sanitized version of typical data is pictured below, and any advice is welcomed. 🙂

 

BDHicks_2-1661352447150.png

 

 

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @BDHicks ,

According to your description, if you want to calculate the duration for each panel ID, here's my solution. Create a measure.

Period =
VAR _MIN =
    MINX (
        FILTER ( 'Table', 'Table'[Panel ID] = MAX ( 'Table'[Panel ID] ) ),
        'Table'[Event Time UTC]
    )
VAR _MAX =
    MAXX (
        FILTER ( 'Table', 'Table'[Panel ID] = MAX ( 'Table'[Panel ID] ) ),
        'Table'[Event Time UTC]
    )
RETURN
    DATEDIFF ( _MIN, _MAX, SECOND )

In my sample below it get the correct result.

vkalyjmsft_0-1661764767309.png

vkalyjmsft_1-1661764782033.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @BDHicks ,

According to your description, if you want to calculate the duration for each panel ID, here's my solution. Create a measure.

Period =
VAR _MIN =
    MINX (
        FILTER ( 'Table', 'Table'[Panel ID] = MAX ( 'Table'[Panel ID] ) ),
        'Table'[Event Time UTC]
    )
VAR _MAX =
    MAXX (
        FILTER ( 'Table', 'Table'[Panel ID] = MAX ( 'Table'[Panel ID] ) ),
        'Table'[Event Time UTC]
    )
RETURN
    DATEDIFF ( _MIN, _MAX, SECOND )

In my sample below it get the correct result.

vkalyjmsft_0-1661764767309.png

vkalyjmsft_1-1661764782033.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

MFelix
Super User
Super User

Hi @BDHicks,

 

To what I can see from the data example yhou provided you have multiple values at the same second, however there is different levels of granularity in this case you have Panel ID and the Reader, have you tried making the sort by those 3 columns and then calculating the values of the duration?

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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