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
sushmitasur4
Regular Visitor

Power BI Hour Difference between two different rows from different column with a condition

Screenshot (466).png

So I am working with Live Data. I need a POWER BI Query to create a calculated column or Measure.

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.

2 REPLIES 2
sushmitasur4
Regular Visitor

Hi Greg, this is the entire table. The Hour Duration is the expected Output

 

Type
2
3
2
3
3
2
3
2
3
 
Start
22-01-2020 18:59
20-01-2020 09:34
20-01-2020 09:34
21-01-2020 09:33
23-01-2020 11:38
23-01-2020 13:38
22-05-2020 17:38
23-05-2020 13:38
24-05-2020 17:38
 
End
22-01-2020 19:59
20-01-2020 10:34
20-01-2020 09:34
21-01-2020 10:33
23-01-2020 11:39
23-01-2020 15:38
22-05-2020 18:38
23-05-2020 15:38

Hours Duration
null
01:00
null
null
01:06
null
01:00
null
null
 
These texts are Column wise.
Greg_Deckler
Community Champion
Community Champion

@sushmitasur4 This is a variation on Previous Row. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

Tough to say, but you might also need Cthulhu. Cthulhu - Microsoft Fabric Community

 

Can you post your data as text and provide the expected output?

 

Or maybe it's simple and you can just do this:

Measure = SUMX( FILTER( 'Table', [Type] = 3 ), [End] - [Start] )

Then convert to seconds and use Chelsie Eiden's Duration? Chelsie Eiden's Duration - Microsoft Fabric Community

 



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
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.