Forum Discussion

Pan_Forex's avatar
Pan_Forex
Icon for Helper III rankHelper III
2 years ago
Solved

row minus previous row

Hello, I am trying to count the difference in points between the latest ID and the previous one for each employee. I have a very simple bug somewhere and I can't find it...  id         emplo...
  • AntrikshSharma's avatar
    2 years ago

    Pan_Forex 

    Total Points = SUM ( pan[points] )
    Output = 
    VAR PreviousValue = 
        CALCULATE ( 
            [Total Points],
            OFFSET ( 
                -1,
                ALL ( pan[employee], pan[id] ),
                ORDERBY ( pan[id], ASC ),
                PARTITIONBY ( pan[employee] )
            )
        )
    VAR CurrentValue = 
        [Total Points]
    VAR GroupingByID = 
        ISINSCOPE ( pan[id] )
    VAR Result = 
        IF ( 
            NOT ISBLANK ( PreviousValue )
                && GroupingByID,
            CurrentValue - PreviousValue
        )
    RETURN
        Result