Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Finding the difference between two filtered Date/Time rows with large data set

Hi All,   I need to create a measure that will subtract two times in seperate rows and provide me with the difference. I need to be able to filter my data using slicers and have the measure calcula...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous,

    AFAIK, power bi data model table not contains row/column index.

    For this scenario, you need to use specific field value as index field(in your DAX expression), then you can extract current row value and lookup table records who contain 'index' value less/large than current row and setting them as previous/next row.

    For example 'DateTime' field:

    CurrentDate =
    MAX ( Table[Date] )
    
    PreviousDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Date] < currentDate )
    )
    
    NextDate =
    CALCULATE (
        MIN( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Date] > currentDate )
    )
    

    Regards,

    Xiaoxin Sheng