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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to find difference between two rows of data?

I have data as shown in a small snippet below. I would like to add a new column that shows the difference from one row to the next. Can anyone show me the DAX code to do this?

 

XYZ1233_0-1647250651930.png

 

1 ACCEPTED SOLUTION

My mistake, I changed my mind about where to put the check for 0 index whilst I was writing it.

Diff to previous = 
var currentIndex = 'Table'[index]
IF( currentIndex > 0,
var currentValue = 'Table'[Value]
var prevValue = LOOKUPVALUE( 'Table'[Value], 'Table'[index], currentIndex - 1)
return currentValue - prevValue
)

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Diff to previous = IF( currentIndex > 0,
var currentIndex = 'Table'[index]
var currentValue = 'Table'[Value]
var prevValue = LOOKUPVALUE( 'Table'[Value], 'Table'[index], currentIndex - 1)
return currentValue - prevValue
)
Anonymous
Not applicable

Hi @johnt75 ,

 

Tried your code but currentIndex on line 1 is greyed out and gives the error "Failed to resolve name 'currentIndex'. Rest of the lines seem to work fine. Any idea how to fix this?

My mistake, I changed my mind about where to put the check for 0 index whilst I was writing it.

Diff to previous = 
var currentIndex = 'Table'[index]
IF( currentIndex > 0,
var currentValue = 'Table'[Value]
var prevValue = LOOKUPVALUE( 'Table'[Value], 'Table'[index], currentIndex - 1)
return currentValue - prevValue
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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 Solution Authors