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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gthistlethwaite
Frequent Visitor

Date Difference Not Working

I have one column with Date of Incident, which is a Date/Time format (01/01/2017 08:00:00), and also a Date of Creation column, which is also the same format as the Date of Incident column.

 

We have a SLA to create the ticket in our system within 72 hours of it happening, and so need a metric to display those users who do not comply.

 

When I try to subtract the created date away from the incident date, I get an unexpected result.

New Custom Column displays -01:49:08.4915213

 

Can anybody tell me if I'm doing something wrong here?

Data is UK Date Format (dd/mm/yyyy hh:mm:ss).

Capture.PNG

 

 

 

 

Many thanks,

Gary

2 ACCEPTED SOLUTIONS

I can see it is done in power query, may be best is to use dax datediff function 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

Well, in Power Query you should get a result back of I believe Days:Hours:Minutes:Seconds. This all works for me here:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMLRQsLAyMAAiBUdfJR2EqCVCNFaHGNVGJKk2sTKFqI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetime}, {"Column2", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Column2]-[Column1])
in
    #"Added Custom"

But, my stuff is all in US. Now, when this gets to DAX I end up getting values like 0.0461666666, 0.043055555, 0.450231481... which is exactly what I get if I do a ([Column2]-[Column1])*1.0 in DAX. There are ways to convert this to something useful but DATEDIFF is going to be your safest bet.

 


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

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Are you trying to do this in Power Query or DAX?


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

DAX is easy, CALCULATE makes DAX hard...

I can see it is done in power query, may be best is to use dax datediff function 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi Greg,

 

The image shows me adding a Custom Column in Edit Quieries.

But I have attempted to add column in DAX with also no joy.

 

Kind regards,

Gary

Well, in Power Query you should get a result back of I believe Days:Hours:Minutes:Seconds. This all works for me here:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMLRQsLAyMAAiBUdfJR2EqCVCNFaHGNVGJKk2sTKFqI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetime}, {"Column2", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Column2]-[Column1])
in
    #"Added Custom"

But, my stuff is all in US. Now, when this gets to DAX I end up getting values like 0.0461666666, 0.043055555, 0.450231481... which is exactly what I get if I do a ([Column2]-[Column1])*1.0 in DAX. There are ways to convert this to something useful but DATEDIFF is going to be your safest bet.

 


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

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.