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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jeffrey_VC
Helper II
Helper II

Next day after timestamp

Hi everyone,

 

I looking for a solution where I have 2 timestamp and will calculate the differents between them.

When i calculate the differents I get a negative value if the first timestamp is later than the second one, like this.
Travel time is differents in minutes.

Jeffrey_VC_0-1711553402709.png

I need the value 1350 (minutes)
How can I solved this?

 

1 ACCEPTED SOLUTION

Hi,

You are correct I had the wrong idea. This should work:

Column =
var _testNextDay =
IF('Table (31)'[time2]<'Table (31)'[time1],
((DATEDIFF("00.00.00",'Table (31)'[time2],MINUTE) -
DATEDIFF("00.00.00",'Table (31)'[time1],MINUTE))
/60
+24)*60
,

 DATEDIFF('Table (31)'[time1],[time2],MINUTE))
 return
 _testNextDay


Here we take the difference in hours = -1 hour then we compare that to 24 hours and multiply by 60. So here 23*60 = 1380

ValtteriN_0-1711615969951.png

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
ValtteriN
Super User
Super User

Hi,

I assume that if the timestamp is lower we will assume it is on next day. Here is an example on how to build this:

ValtteriN_0-1711562278067.png

 

Dax:

Column =
var _testNextDay =
IF('Table (31)'[time2]<'Table (31)'[time1],
DATEDIFF("00.00.00",'Table (31)'[time2],MINUTE)+720,

 DATEDIFF('Table (31)'[time1],[time2],MINUTE))
 return
 _testNextDay


End result:

ValtteriN_1-1711562675215.png

 

If the time is lower we add 12 hours in minutes (720) and compare the second time to midnight. Otherwise we compare normally.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/








Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you @ValtteriN , this works! Thank you for your help.

Hi @ValtteriN ,
Thank you for your quick answer.
Your solution is not the solution that i need.

Time 1: 14:00
Time 2: 13:00

Different is 1350 minutes and not 1500 minutes so you have in your example.

Hi,

You are correct I had the wrong idea. This should work:

Column =
var _testNextDay =
IF('Table (31)'[time2]<'Table (31)'[time1],
((DATEDIFF("00.00.00",'Table (31)'[time2],MINUTE) -
DATEDIFF("00.00.00",'Table (31)'[time1],MINUTE))
/60
+24)*60
,

 DATEDIFF('Table (31)'[time1],[time2],MINUTE))
 return
 _testNextDay


Here we take the difference in hours = -1 hour then we compare that to 24 hours and multiply by 60. So here 23*60 = 1380

ValtteriN_0-1711615969951.png

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.