Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Calculate time difference by matching ids

Hi, im trying to do something like this 

 

 

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!

  • 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

2 Replies

  • Stachu's avatar
    Stachu
    Icon for Community Champion rankCommunity 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
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the help!

      It is working