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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
MikeLanglois
Frequent Visitor

Find time difference (hh:mm:ss) between two datetimes

Hey all,

 

I am probably missing something stupidly easy, but I have two columns:

 

Date 1Date 2
31/01/2022 08:12:0131/01/2022 09:32:46
31/01/2022 08:10:5331/01/2022 08:12:26
31/01/2022 07:58:5031/01/2022 08:03:30

 

What I am trying to achieve is a column or measure that can tell me the difference between these two fields, for example it would look like:

Date 1Date 2Difference
31/01/2022 08:12:0131/01/2022 09:32:4601:20:45
31/01/2022 08:10:5331/01/2022 08:12:2600:01:33
31/01/2022 07:58:5031/01/2022 08:03:3000:04:40

 

But I cant seem to make this happen? When I try a measure of simply date2-date1, it doesnt work. Datediff doesnt let me choose my date1/2 fields to put into the measure. I add a column into the data query to generate it row by row but when I try to convert that value to time it errors saying it cant be done on a direct query dashboard?

 

Any help greatly appreciated!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@MikeLanglois You need to convert the hh:mm:ss to seconds, perform the subtraction and then convert back to hh:mm:ss or use Chelsie Eiden's duration to keep it as a numeric value with a custom format string.

Duration to Seconds Converter - Microsoft Power BI Community

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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@MikeLanglois You need to convert the hh:mm:ss to seconds, perform the subtraction and then convert back to hh:mm:ss or use Chelsie Eiden's duration to keep it as a numeric value with a custom format string.

Duration to Seconds Converter - Microsoft Power BI Community

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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thanks for the links. What an incredibly long winded way of doing one value minus another! Assumed it would be that simple as it is on other Microsoft products.

 

Anyway thanks again

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors