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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
jereaallikko
Helper III
Helper III

How to Calculate Time difference from MIN Timestamp and MAX Timestamp in same Column

Hi all,

 

I am trying to calculate a time difference (ideally on hh/mm/ss format) from different rows from earliest timestamp and latest timestamp.

 

My data contains ID and Timestamp (date/time) columns (and many more). Here is a sample data:

SampleData.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I'm trying to calculate the ddhhmm difference between earliest timestamp and the last one from each ID. So like this:

SAMPLECalculation.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

So the end result should look like this in HH/MM/SS format, DD/HH/MM/SS would be also nice to have:

SampleSolution.JPG

 

 

 

 

Any tips?

 

Thanks,

Jere

2 ACCEPTED SOLUTIONS
Whitewater100
Solution Sage
Solution Sage

Hi jer:

 

You could do a few measures.

MIN Time value = CALCULATE(MIN(Data[Time]), ALLEXCEPT(Data,Data[ID]))
MAx Time value = CALCULATE(MAX(Data[Time]), ALLEXCEPT(Data,Data[ID]))
Time Difference H = DIVIDE( DATEDIFF([MIN Time value],[MAX Time value],MINUTE),60)
 
Here's the result using some of my data:(Please note format is LongTime)
Whitewater100_0-1652360190081.png

My Data table named Data

Whitewater100_1-1652360272415.png

 

 

View solution in original post

Anonymous
Not applicable

Hi @jereaallikko ,

 

Please check this measure.

Measure = 
VAR min_ = CALCULATE(MIN('Table'[timestamp]),ALLEXCEPT('Table','Table'[ID]))
VAR max_ = CALCULATE(MAX('Table'[timestamp]),ALLEXCEPT('Table','Table'[ID]))
var vSeconds=DATEDIFF(min_,max_,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
vDays&" "&
  vRemainingHours&":"&
  vRemainingMinutes&":"& 
  vRemainingSeconds

vjaywmsft_0-1652776888334.png

 

Best Regards,

Jay

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @jereaallikko ,

 

Please check this measure.

Measure = 
VAR min_ = CALCULATE(MIN('Table'[timestamp]),ALLEXCEPT('Table','Table'[ID]))
VAR max_ = CALCULATE(MAX('Table'[timestamp]),ALLEXCEPT('Table','Table'[ID]))
var vSeconds=DATEDIFF(min_,max_,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
vDays&" "&
  vRemainingHours&":"&
  vRemainingMinutes&":"& 
  vRemainingSeconds

vjaywmsft_0-1652776888334.png

 

Best Regards,

Jay

Arul
Super User
Super User

@Whitewater100 ,

also check out this thread

https://community.powerbi.com/t5/Desktop/Sum-timestamp-based-on-Min-Max-and-Sum-all-lines/m-p/201437... 





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

Proud to be a Super User!


LinkedIn


Whitewater100
Solution Sage
Solution Sage

Hi jer:

 

You could do a few measures.

MIN Time value = CALCULATE(MIN(Data[Time]), ALLEXCEPT(Data,Data[ID]))
MAx Time value = CALCULATE(MAX(Data[Time]), ALLEXCEPT(Data,Data[ID]))
Time Difference H = DIVIDE( DATEDIFF([MIN Time value],[MAX Time value],MINUTE),60)
 
Here's the result using some of my data:(Please note format is LongTime)
Whitewater100_0-1652360190081.png

My Data table named Data

Whitewater100_1-1652360272415.png

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.