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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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