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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@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


@ 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!:
The Definitive Guide to Power Query (M)

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
Super User
Super User

@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


@ 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!:
The Definitive Guide to Power Query (M)

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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