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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
analyst123
Frequent Visitor

Question about DAX Formula for calculating time difference

Hi,

I am trying to calculate the duration (in minutes) between two columns in Power BI. The columns look like this:

analyst123_0-1724356494895.png

Unfortunately when I tried to simply add a custom column with the formula = "Column 2" - "Column 1", it only worked properly for a few of the rows but keeps giving the wrong answers for others. If I try splitting this column into two (seperating the time and date), I end up losing the seconds for the time. So if anyone can please help me with the DAX code for this or any other altenrate way?

1 ACCEPTED SOLUTION
muhammad_786_1
Super User
Super User

There are multiple ways to solve this problem.

You can also do it by using this measure.

 

Duration in Minutes=
DATEDIFF(MIN('Sheet1'[Column1]), MIN('Sheet1'[Column2]), MINUTE) +
(SECOND(MIN('Sheet1'[Column2])) - SECOND(MIN('Sheet1'[Column1]))) / 60

 

muhammad_786_1_1-1724360445891.png

 

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

Follow on LinkedIn

View solution in original post

4 REPLIES 4
muhammad_786_1
Super User
Super User

There are multiple ways to solve this problem.

You can also do it by using this measure.

 

Duration in Minutes=
DATEDIFF(MIN('Sheet1'[Column1]), MIN('Sheet1'[Column2]), MINUTE) +
(SECOND(MIN('Sheet1'[Column2])) - SECOND(MIN('Sheet1'[Column1]))) / 60

 

muhammad_786_1_1-1724360445891.png

 

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

Follow on LinkedIn

Hello @muhammad_786_1 ,

Thank you for your help. The formula works but there is only one issue that I am facing. It gives me negative values as shown below. Is there anyway to add another function for these specific kind of issues?

analyst123_1-1724417388890.png

 

I also had one more question. The formula works well and shows the correct duration for each row. I am unable to get a total when i add it to the table.

analyst123_0-1724422765738.png

And even when I click on the data column, it does not give me the option to make it into a total.

analyst123_1-1724422779734.png

 I appreciate you for your help! Please let me know. Thank you!

I designed the formula with the assumption that 'Column1' represents the earlier date and 'Column2' the later date. However, if there’s a possibility that 'Column2' could be an earlier date than 'Column1', you can simply put the entire calculation in the ABS() function. This will ensure that the result is always positive, regardless of the order of the dates.

 

For the issue with the total, we can also do this by creating a calculated column, especially if the performance impact is minimal. This approach ensures that the total is calculated correctly. You can also check this attached file.

 

File

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

Follow on LinkedIn

 

Greg_Deckler
Community Champion
Community Champion

@analyst123 The formula should be:

 

Column = ([Column2] - [Column1]) * 60 * 60

 



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

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors