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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
apvu2
Helper I
Helper I

How to subtract Row Values (previous Row Value) grouped by Name

I was wondering if there was a way to subtract a previous row value grouped by lets say Name. The screenshot of what I am trying to achieve is below. If there was no previous row for the individual there wouldnt be a value to subtract. I also sorted name and year by ascending order. In power query or Dax it does not matter, I just need that difference column. 

 

apvu2_0-1666627693976.png

 

(Same Table Copy and pasted) 

 

NameYearDifference
A2019N/A
A20201
A20211
B2020N/A
B20211
C2019N/A
C20223
C20231
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@apvu2 Try:

Difference Column = 
  VAR __Name = [Name]
  VAR __Year = [Year]
  VAR __Previous = MAXX(FILTER('Table',[Name] = __Name && [Year] < __Year),[Year])
RETURN
  __Year - __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

@apvu2 Try:

Difference Column = 
  VAR __Name = [Name]
  VAR __Year = [Year]
  VAR __Previous = MAXX(FILTER('Table',[Name] = __Name && [Year] < __Year),[Year])
RETURN
  __Year - __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

Hi @Greg_Deckler ,

 

I'm trying to use your formula here, but it seems like the formula can't detect my column name, as it only detect for "measure". May i know why and how do i fix this ?

Hey Greg, 

Thank you so much this would definitely work!!!!!!!!!!!!!!!!!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors