Forum Discussion

MattRoed's avatar
MattRoed
Helper I
6 years ago
Solved

Custom Column to Reverse a Running Total

I would like a column that can reverse a column that is keeping track of a running total.  Trap DateCaptured Count Change 1000 1/1/2020 0 0 1000 1/8/2020 101 101 1000 1/15/2020...
  • mahoneypat's avatar
    6 years ago

    Please try this expression your column

     

    Change =
    VAR __thisvalue = Traps[Count]
    VAR __thisdate = Traps[DateCaptured]
    VAR __prevdate =
        CALCULATE (
            MAX ( Traps[DateCaptured] ),
            ALLEXCEPT ( Traps, Traps[Trap] ),
            Traps[DateCaptured] < __thisdate
        )
    VAR __prevvalue =
        CALCULATE (
            MAX ( Traps[Count] ),
            ALLEXCEPT ( Traps, Traps[Trap] ),
            Traps[DateCaptured] = __prevdate
        )
    RETURN
        __thisvalue - __prevvalue

     

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

    Regards,

    Pat