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
Lazurens
Frequent Visitor

Calculating Time Duration with Lag: How to Measure the Time Between Two Events with a One-Step Delay

Hello, 

I would like to calculate the duration in seconds between two events spent on the same equipment tool.

 

 

DurationInSeconds = 
VAR Current_DateTime = MAX(UTILITY_HISTORY[EV_TIME])
VAR T1 =
    CALCULATETABLE (
        'UTILITY_HISTORY',
        ALLEXCEPT ( 'UTILITY_HISTORY', 'UTILITY_HISTORY'[EQUIP_ID] )
    )
VAR T2 =
    FILTER ( T1, UTILITY_HISTORY[EV_TIME] < Current_DateTime )
VAR T3 =
    TOPN ( 1, T2, UTILITY_HISTORY[EV_TIME], DESC )
VAR NextDateTime =
    SELECTCOLUMNS ( T3, "@DateTime", UTILITY_HISTORY[EV_TIME] )
VAR Result =
    IF ( NOT ISBLANK ( NextDateTime ), Current_DateTime - NextDateTime )
RETURN
    Result

 

 

Lazurens_0-1699276314249.png

Can anyone please help me figure out how list durations starting from step-1 ?

I appreciate any help to make it work. 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Lazurens , Use offset function

 

New measure = Calculate(Max(Table[Duartion]), offset(-1, allselected(Table[Equip], Table[EV_time]), Orderby([EV_time],asc) )

 

Continue to explore Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Lazurens , Use offset function

 

New measure = Calculate(Max(Table[Duartion]), offset(-1, allselected(Table[Equip], Table[EV_time]), Orderby([EV_time],asc) )

 

Continue to explore Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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