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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
lawada
Helper III
Helper III

duration between 2 dates with time (AM/PM)

i need a quick help with this:

 

im trying to find the duration between two dates with dax however theres something wrong with the formula as  calculating time not correctly and its not considering when the time in the date is AM or PM

first,i used the formula the calculate the diffrenece between the two dates in seconds:

Duration in Seconds= datediff(order pickup date, order cancelation date, second)

after that i wanted to find the duration separated into (days,hours,minutes,seconds) so i used this formula:

duration =

var d= SUM(orders[Duration in Seconds])
var vMinutes=int( d/60)
var vRemainingSeconds=MOD(d, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
vDays&" Days & "&
vRemainingHours&" Hours & "&
vRemainingMinutes&" Minutes & "&
vRemainingSeconds& " Seconds"

 

this is an example of how im getting the result:

 
 
 

tt.PNG

 

 

 

for the highlted row , its calculating -1 day however result should be  0 hours, 48 minutes and 7 seconds

2 REPLIES 2
abodqm
Regular Visitor

 i can i sum all time to show total with this measure ??? if i want to se a client orders and see times taken for example i want to sum the time with this measure

Fowmy
Super User
Super User

@lawada 

You can use a single measure without having to create a column, please try below as a measure:

 

Duration Between Cancell and Pickup = 
var vSeconds=DATEDIFF(MAX(Orders[order pickup date]),MAX(Orders[order cancelation date]),SECOND)
var vMinutes=int( vSeconds/60)
var vRemainingSeconds=MOD(vSeconds, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
IF( 
   vSeconds > 0 , 
    vDays&" Days & "&
    vRemainingHours&" Hours & "&
    vRemainingMinutes&" Minutes & "& 
    vRemainingSeconds& " Seconds"
  ,
    BLANK()
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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