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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
DonPepe
Helper II
Helper II

Time Delta with negative hour handling

Good Afternoon, 

 

I am currently looking for a solution to get the duration between two Date-Time value.

 

The issue is that I have to handle positivie and negative hour like in these 3 different scenarios : 

  • End time > Start time 
  • End time < Start time
  • End date <> Start date 

Here an exemple of the 3 scenarios. 

Activity Type             Start time             End time 

Drive20-10-21 00:0620-10-21 00:11
Time correction 20-10-21 01:1020-10-21 00:06
Drive 20-10-21 23:0621-10-21 00:22

 

Do you know how I can have the duration in hh:mm:ss of each activity ? 

 

Thank's in advance,

 

Don 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@DonPepe Just subtract them then turn that into seconds and then you can use Chelsie Eiden's duration.

Column = ([Start] - [End]) * 1. * 24 * 60 * 60

Chelsie Eiden's Duration - Microsoft Power BI 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...

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Simple enough to handle it in PQ,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcinKLEtV0lEyMtA1NNA1MlQwMLAyMEMTMDRUitWJVgrJzE1VSM4vKkpNLsnMzzu0AEWZoZWhAaZBIH1gO1BVGxlDbTFCqDYyUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Activity Type" = _t, #"Start time" = _t, #"End time" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity Type", type text}, {"Start time", type datetime}, {"End time", type datetime}}, "fr"),
    Dur = Table.AddColumn(#"Changed Type", "Duration", each let dur = List.Max({[End time]-[Start time], [Start time]-[End time]}) in Text.Format("#{0}h : #{1}m : #{2}s", {Number.RoundDown(Duration.TotalHours(dur)), Duration.Minutes(dur), Duration.Seconds(dur)}))
in
    Dur

 

Screenshot 2021-10-29 204507.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL,

 

Thanks a lot, I tried in Power query and it works but I was loking for a DAX solution. 

 

 

Greg_Deckler
Community Champion
Community Champion

@DonPepe Just subtract them then turn that into seconds and then you can use Chelsie Eiden's duration.

Column = ([Start] - [End]) * 1. * 24 * 60 * 60

Chelsie Eiden's Duration - Microsoft Power BI 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...

Hi @Greg_Deckler ,

 

Thanks for your answer and for the link to your book, I need it also ! 

 

Excellent day,

 

Don 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.