Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Calculate the difference between each previous value in a column for matching items only

Good day, Community. I am working on a project where I need to calculate the difference in [Cycles] for like [Registration] values for each previous instance of an event in a table, where the orde...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Disregard... Just got it to work. Thank you for looking, though! Leaving this hear in case anyone else could use.

     

     

    Cycles Since Previous = 
    VAR CurrentReg = 'Table'[Registration]
    VAR CurrentKEY = 'Table'[PRIMARYKEY]
    VAR PrevKEY = CALCULATE(
        MAX('Table'[PRIMARYKEY]),
        FILTER(
            'Table',
            'Table'[PRIMARYKEY] < CurrentKEY &&
            'Table'[Registration] = CurrentReg
        )
    )
    RETURN
    IF(
        ISBLANK(PrevKEY),
        BLANK(),
        'Table'[ Cycles ] - 
        CALCULATE(
            MAX('Table'[ Cycles ]),
            FILTER(
                'Table',
                'Table'[PRIMARYKEY] = PrevKEY
            )
        ))