Forum Discussion

sarvesh23p's avatar
sarvesh23p
New Member
3 years ago
Solved

Compare current record with previous record within same column on the basis date-time column

Hi All,   I have a table which have Date tiem columns and a data columns. Consider column name  'high' I want to compare recirds with the previous value on same column on the basis on datetime col...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi sarvesh23p ,

     

    Please try this code to create a measure.

    Open Diff =
    VAR _Previous_Datetime =
        CALCULATE (
            MAX ( 'Table'[Datetime] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Datetime] < MAX ( 'Table'[Datetime] ) )
        )
    VAR _Previous_value =
        CALCULATE (
            SUM ( 'Table'[Open] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Datetime] = _Previous_Datetime )
        )
    VAR _Current_value =
        CALCULATE ( SUM ( 'Table'[Open] ) )
    RETURN
        _Current_value - _Previous_value

    My Sample:

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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