Forum Discussion

Unknown's avatar
Unknown
Frequent Visitor
4 years ago
Solved

Difference between two rows

Hello, I have a table that looks like this (Please note that my date is in the format DD/MM/YYYY): I want to calculate the difference between two following dates where condition=1. I man...
  • tamerj1's avatar
    4 years ago

    Hi Unknown 
    You can use

     

     

    datediff =
    VAR CurrentDate = 'Table'[date]
    VAR PreviousTable =
        FILTER (
            'Table',
            'Table'[date] < CurrentDate
                && 'Table'[condition] <> BLANK ()
        )
    VAR PreviousDate =
        MAXX ( PreviousTable, 'Table'[date] )
    RETURN
        IF (
            'Table'[condition] = 1
                && NOT ISEMPTY ( PreviousTable ),
            DATEDIFF ( PreviousDate, CurrentDate, DAY )
        )