Forum Discussion

Birinder's avatar
Birinder
Helper III
3 years ago
Solved

How to add previous row value in current row value while having 2 categorical variables ?

Hi Community, I have a dataset table named as "IBNS". Under it, I have 3 columns as follow:- 1. KEY (Data type - text) 2. Date (Data type - Short Date) 3. RRT - (Data type - Decimals)   I want...
  • barritown's avatar
    barritown
    3 years ago

    Hi Birinder

    Sure, please try this CC:

    And the same in plain text:

    PrevSum v2 = 
    VAR CurrentKey = [KEY]
    VAR CurrentDate =  [Date]
    VAR PrevYear = CALCULATE ( YEAR ( MAX ( data[Date] ) ), ALL ( data ), data[KEY] = CurrentKey, data[Date] < CurrentDate )
    VAR PrevRRT = MINX ( FILTER ( ALL ( data ), AND ( [KEY] = CurrentKey, YEAR ( [Date] ) = PrevYear ) ), [RRT] )  
    RETURN IF ( ISBLANK ( PrevRRT ), 0, [RRT] + PrevRRT )

    Best Regards,

    Alexander

    My YouTube vlog in English

    My YouTube vlog in Russian