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
BGlost
New Member

Time difference

Hi,

 

I'm trying to get a total time it takes from the starting time of 1:06:42pm until 7:59:47pm. The answer would be... 6hrs 53 min and 5 secs. Any ideas how to accomplish this?

 

BGlost_0-1614108090279.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BGlost ,

 

According to my understanding, you want to convert timediff to the format of Hour&Minute&Second,right?

Please try this:

Hour&Min&Sec = 
VAR _diff =
    DATEDIFF ( MAX ( 'Table'[Start] ), MAX ( 'Table'[End] ), SECOND )
VAR _h =
    MOD ( INT ( _diff / ( 60 * 60 ) ), 24 )
VAR _m =
    MOD ( INT ( _diff / 60 ), 60 )
VAR _s =
    MOD ( _diff, 60 )
RETURN
    _h & "hrs " & _m & "mins " & _s & "secs"

The final output is shown below:

2.26.1.timediff.PNG

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @BGlost ,

 

According to my understanding, you want to convert timediff to the format of Hour&Minute&Second,right?

Please try this:

Hour&Min&Sec = 
VAR _diff =
    DATEDIFF ( MAX ( 'Table'[Start] ), MAX ( 'Table'[End] ), SECOND )
VAR _h =
    MOD ( INT ( _diff / ( 60 * 60 ) ), 24 )
VAR _m =
    MOD ( INT ( _diff / 60 ), 60 )
VAR _s =
    MOD ( _diff, 60 )
RETURN
    _h & "hrs " & _m & "mins " & _s & "secs"

The final output is shown below:

2.26.1.timediff.PNG

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

Portrek
Resolver III
Resolver III

You can use a measure, i feel little faster loading time with this


TimeDiff = CONVERT(SELECTEDVALUE(Table[Date1],0)-SELECTEDVALUE(Table[Date2],0),DATETIME)


and then change the format to time hh:mm:ss


or maybe this post below help you..


https://community.powerbi.com/t5/Desktop/Calculating-day-time-difference/m-p/321189

Cheers

KayceVC
Helper II
Helper II

 Have you tried using DATEDIFF yet? It's fairly simple to add and allows you to define your start, end and chosen interval (hours, seconds, days, etc).

 

Knowledge Base: https://docs.microsoft.com/en-us/dax/datediff-function-dax

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.