Forum Discussion

WorkHard's avatar
WorkHard
Helper V
5 years ago
Solved

Date Difference between two values in the same column with same Id

I'm trying to calculate the difference in days between two values in the same column that have the same id. Consider the following data: -EventId- -Start Date- -Desired Result- Event1 1/15...
  • v-janeyg-msft's avatar
    5 years ago

    Hi, WorkHard 

     

    You can create a column to calculate the dasired result.

    Like this:

     

    column = 
    VAR a =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                [-Snapshot Date-] < EARLIER(  'Table'[-Snapshot Date-] )
                    && [-EventId-] = EARLIER(  'Table'[-EventId-] )
            ),
            [-Snapshot Date-]
        )
    VAR b =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                [-Snapshot Date-] = a
                    && [-EventId-] = EARLIER(  'Table'[-EventId-] )
            ),
            [-StartDate-]
        )
    RETURN
        DATEDIFF ( b, 'Table'[-StartDate-] , DAY )
    

     

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.