Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

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
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

 

But basically what you want is something like this:

 

Difference = 
  VAR __Previous = MAXX(FILTER('Table',[PersonName] = EARLIER([PersonName] && [Index] = EARLIER([Index]) - 1),[Amount])
RETURN
  IF([Index]=1,0,[Amount] - [Previous])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

 

But basically what you want is something like this:

 

Difference = 
  VAR __Previous = MAXX(FILTER('Table',[PersonName] = EARLIER([PersonName] && [Index] = EARLIER([Index]) - 1),[Amount])
RETURN
  IF([Index]=1,0,[Amount] - [Previous])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
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])

Awesome! Glad it worked!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.