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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Aftab
New Member

How to get duration in hours between 2 date/time

Hello Everyone,

 

I am new to PowerBi and need help finding a solution to the below problem.

 

I have 2 columns in my excel datasource, 'Created Date Time' and 'Time Resolved', I need help creating a column or a measure to calculate the difference between these to date-Time, and need the desied output to be in hh:mm:ss format.

I can easily do that in excel, by subtracting the start date/time from end date/time and then changing the cell format to Time, however finding it difficult to achieve in PowerBi.

 

Below is a screenshot from excel with desired Output.

 

Data:

CategoryCreated Date TimeTime ResolvedResolve Duration (Desired Output)
Task 18/3/2018 10:448/3/2018 14:564:12:00
Task 18/1/2018 11:588/1/2018 17:125:14:00
Task 18/22/2018 14:188/23/2018 10:5020:32:00
Task 18/23/2018 17:338/24/2018 14:3421:01:00
Task 18/7/2018 17:228/8/2018 15:4922:27:00
Task 18/9/2018 14:048/29/2018 14:32480:28:00
Task 18/2/2018 17:038/29/2018 12:14643:11:00
Task 28/2/2018 8:148/29/2018 17:27657:13:00
Task 28/2/2018 12:508/2/2018 13:020:12:00
Task 28/3/2018 9:078/27/2018 11:23578:16:00
Task 28/14/2018 12:498/15/2018 14:2825:39:00
Task 28/14/2018 15:438/14/2018 15:450:02:00
Task 28/14/2018 16:518/14/2018 17:050:14:00
Task 28/15/2018 12:418/21/2018 16:06147:25:00
Task 28/16/2018 8:498/21/2018 10:08121:19:00

 

When Pivotted.

 

Pivot.JPG

 

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi Aftab,

 

To achieve your requirement, create a calculate column using DAX as below:

Result = 
VAR interval = DATEDIFF(Table1[Created Date Time], Table1[Time Resolved], SECOND)
VAR hour = INT(interval / 3600)
VAR minute = INT((interval - hour * 3600) / 60)
VAR second = MOD(interval, 60)
RETURN
HOUR & ":" & minute & ":" & second

Capture.PNG  

 

Regards,

Jimmy Tao

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi Aftab,

 

To achieve your requirement, create a calculate column using DAX as below:

Result = 
VAR interval = DATEDIFF(Table1[Created Date Time], Table1[Time Resolved], SECOND)
VAR hour = INT(interval / 3600)
VAR minute = INT((interval - hour * 3600) / 60)
VAR second = MOD(interval, 60)
RETURN
HOUR & ":" & minute & ":" & second

Capture.PNG  

 

Regards,

Jimmy Tao

Greg_Deckler
Community Champion
Community Champion

Date/Time column in Power BI is really just a decimal value where the integer portion is the number of days and the decimal portion is the time component. You could potentially use DATEDIFF with the HOUR option. Or do it manually, here is an old article on aggregating duration in Power BI. https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486



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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.

Top Solution Authors