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

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

Reply
sushmitasur4
Regular Visitor

Hour Duration between two different rows from different columns in Power BI

Screenshot (466).png

So I am working with Live Data in POWER BI. I need a Query.

What I really want is the Sum of Hours between (Start time when type = 3) and (End time when type = 3)

Basically, It starts when type = 3 and records the start time. The counter Goes on until type goes back to type = 2 and records the previous row and records the End time and then calculates the Duration between them. 

The Hour Duration column is my desired Output.

Output Explanation:

I subtract the end time 23-01-2020 11:39 with the start time of previous row 21-01-2020 09:33.

5 REPLIES 5
Anonymous
Not applicable

Hi @sushmitasur4 ,

You can follow the steps below to get it:

1. Add index column in Power Query Editor

= Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)

vyiruanmsft_0-1708587452103.png

2. Create a calculated column as below

Column = 
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Type] = EARLIER ( 'Table'[Type] )
                && 'Table'[Index]
                    = EARLIER ( 'Table'[Index] ) - 1
        )
    )
VAR _prestart =
    CALCULATE (
        MAX ( 'Table'[Start] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( ISBLANK ( _count ), BLANK (), DATEDIFF ( _prestart, 'Table'[End], HOUR ) )

vyiruanmsft_1-1708587526215.png

Best Regards

The table below is the reference. The Hour Duration is the expected Output actually.

Screenshot (468).png

Anonymous
Not applicable

Hi @sushmitasur4 ,

Why the Hours Duration is "01:06:00" when Index is 5? Could you please provide the related calculation logic?

vyiruanmsft_0-1708653543448.png

Best Regards

Here's the Pseudo Code of the logic calculation I need:

 

BypassedHoursColumn =

When typecolumn = 3: Variable MinTime = Start_TimeStamp

When typecolumn !=3:

IF PreviousRow((End_TimeStamp)) == Non-Blank: 

Variable MaxTime = PreviousRow((End_TimeStamp)) and Store (MaxTime - MinTime)

IF PreviousRow((End_TimeStamp)) == Blank: 

Variable MaxTime = PreviousRow((End_TimeStamp)) and Store (NOW() - MinTime)

Greg_Deckler
Community Champion
Community Champion

@sushmitasur4 Cross posted. See answer in other thread.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

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