Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

calculate Difference from previous date

Good day,   Can anyone help me to get below output column in DAX.  I want to calculate difference between values columns based on Dates column   name DATES VALUES output A 08-12-2019 0...
  • mahoneypat's avatar
    6 years ago

    This expression works in a calculated column to get your desired result.  Replace "Data" throughout with your actual table name.

     

    Previous Value =
    VAR thisdatetime = Data[DATES]
    VAR prevdatetime =
        CALCULATE (
            MAX ( Data[DATES] ),
            ALLEXCEPT ( Data, Data[name] ),
            Data[DATES] < thisdatetime
        )
    RETURN
        CALCULATE (
            MIN ( Data[VALUES] ),
            ALLEXCEPT ( Data, Data[name] ),
            Data[DATES] = prevdatetime
        )

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat