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
Anonymous
Not applicable

Calculate time difference by matching ids

Hi, im trying to do something like this 

 

sdfsdf.PNG

 

When id matchs, it calculates the time difference with the previous record

 

I think in something with earlier function and filter but i couldnt make it work

 

Any ideas?

Thanks!

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

EARLIER refers to the filter context, not to the date/position in table
try this

Column = 
VAR _id = 'Table'[id]
VAR _created = 'Table'[created]
VAR _previousDate = CALCULATE(MAX('Table'[created]),FILTER(ALL('Table'),'Table'[id] = _id && 'Table'[created] < _created))
VAR _handleBlanks = IF(ISBLANK(_previousDate),_created,_previousDate)
RETURN
_created-_handleBlanks


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

2 REPLIES 2
Stachu
Community Champion
Community Champion

EARLIER refers to the filter context, not to the date/position in table
try this

Column = 
VAR _id = 'Table'[id]
VAR _created = 'Table'[created]
VAR _previousDate = CALCULATE(MAX('Table'[created]),FILTER(ALL('Table'),'Table'[id] = _id && 'Table'[created] < _created))
VAR _handleBlanks = IF(ISBLANK(_previousDate),_created,_previousDate)
RETURN
_created-_handleBlanks


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Thanks for the help!

It is working

 

 

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.