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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kenblack
Helper I
Helper I

calculating duration

I have two columns both in the following format

 

04/06/2020 05:02:00 so dd/mm/yyyy hh/mm/ss and I would like to subtract one from the other to get the duration in hrs - can anyone help please

 

Thankyou in advance 

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

Use the Duration.TotalHours() function in Power Query. Just subtract column 1 from column 2. It will return total and fractional hours.

edhans_0-1596473705595.png

If you just need hours, round it using Number.Round(formula, 0) 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@kenblack - If you need net work duration, you can use this: https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Duration-Working-Hours/m-p/481543#M...



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

@kenblack ,

[Date1]-[date2] will give duarion

datediff([Date1],[Date2], hour) will give diff in hours

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
DataZoe
Microsoft Employee
Microsoft Employee

@kenblack You can also do this in DAX with the DATEDIFF function https://docs.microsoft.com/en-us/dax/datediff-function-dax

 

Hours Difference = DATEDIFF([Start],[End],HOUR)

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

edhans
Community Champion
Community Champion

Yes, if you need this in a measure, DATEDIFF() will work well. If you need a column, Power Query is generally a better choice for performance than a calculated column. So depends on how you are using this.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Community Champion
Community Champion

Use the Duration.TotalHours() function in Power Query. Just subtract column 1 from column 2. It will return total and fractional hours.

edhans_0-1596473705595.png

If you just need hours, round it using Number.Round(formula, 0) 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.