Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Need to find difference between consecutive rows with Index sequence repeating based on criteria

Need to create a calculated column in Power Bi Named "Difference_Amount". There is an Index (sequence) column. But that restarts based on a new person's name. When the Index is 1 then "Difference_Amount" becomes 0.

 

PersonNameDateAddedIndexAmountDifference_Amount
Person A2/15/20201450
Person A2/16/20202450
Person A2/17/2020348-3
Person A2/18/20204408
Person A2/19/20205400
Person A2/20/20206400
Person A2/21/20207400
Person A2/22/20208400
Person A2/23/20209400
Person A2/24/202011328
Person A2/25/20201040-8
Person A2/26/20201248-8
Person A2/27/202018408
Person A2/28/202019400
Person A2/29/202020400
Person A3/1/20201356-16
Person A3/2/202014488
Person A3/3/202015408
Person A3/4/202016328
Person A3/5/20201748-16
Person B2/15/20201740
Person B2/16/20202740
Person B2/17/20203740
Person B2/18/20204740
Person B2/19/20205740
Person B2/20/20206740
Person B2/21/20207740
Person B2/22/20208740
Person B2/23/20209740
Person B2/24/2020103440
Person B2/25/202011340
Person B2/26/202012340
Person B2/27/20201450-16
Person B2/28/202015500
Person B2/29/202016500
Person B3/1/202013500
Person B3/2/202017428
Person B3/3/202018348
Person B3/4/20201950-16
Person B3/5/202020500

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you so much Greg_Deckler . This works well for me. There is a minor syntax issue - After 

      EARLIER([PersonName]

      there is a closing round braces.  

      The expression which works for me is pasted below

      Difference = Var _Previous = MAXX(
                  FILTER('Table',
                          'Table'[PersonName] = EARLIER('Table'[PersonName]) && 
                          'Table'[Index] = EARLIER('Table'[Index]) - 1),
                          'Table'[Amount])
      Return  If('Table'[Index]=1,0,_Previous-'Table'[Amount])