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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calcualte Difference/% Change between two rows.

Hi there,

 

I have the following data:

 

Date  SPX Price    Volume

7/9/20203152.054829020000
7/8/20203169.944927700000
7/7/20203145.324563700000
7/6/20203179.724736450000
7/2/20203130.014190830000
7/1/20203115.864443130000
6/30/20203100.294696280000
6/29/20203053.244462770000
6/26/20203009.058098120000
6/25/20203083.764815420000
6/24/20203050.335587200000
6/23/20203131.294704830000
6/22/20203117.864665380000
6/19/20203097.748327780000
6/18/20203115.344429030000
6/17/20203113.494549390000
6/16/20203124.745829240000
6/15/20203066.595740660000
6/12/20203041.315832250000
6/11/20203002.17018890000
6/10/20203190.146570840000
6/9/20203207.186382620000
6/8/20203232.398437380000

 

I want to add a third column that calculates the % change in Price between two adjacent dates. Is this possible? Thanks.

1 ACCEPTED SOLUTION

@calerof , the correct version. Value replacement issue in my formula

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

13 REPLIES 13
az38
Community Champion
Community Champion

Hi @Anonymous 

try a measure like

Measure = 
var _prevDate = CALCULATE(MAX(Table[Date]), Table[Date] < MAX(Table[Date]))
var _prevPrice = CALCULATE(MAX(Table[SPX Price]), Table[Date] = _prevDate )
RETURN
DIVIDE(MAX(Table[SPX Price]), _prevPrice)

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

"A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

 

That is the error that comes with the measure.

az38
Community Champion
Community Champion

@Anonymous 

yes, sorry

Measure = 
var _curDate = MAX(Table[Date]) 
var _prevDate = CALCULATE(MAX(Table[Date]), Table[Date] < _curDate )
var _prevPrice = CALCULATE(MAX(Table[SPX Price]), Table[Date] = _prevDate )
RETURN
DIVIDE(MAX(Table[SPX Price]), _prevPrice)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
calerof
Impactful Individual
Impactful Individual

Hi @az38,

I'm following your solution and don't get the previous price:

PrevPrice.png

Could you please advise?

F

az38
Community Champion
Community Champion

@calerof 

it should work better

Measure = 
var _curDate = MAX('Table'[Date]) 
var _prevDate = CALCULATE(MAX('Table'[Date]), 'Table'[Date] < _curDate, ALL('Table') )
var _prevPrice = CALCULATE(MAX('Table'[SPX Price]), 'Table'[Date] = _prevDate, ALL('Table') )
RETURN
DIVIDE(MAX(Table[SPX Price]), _prevPrice)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
az38
Community Champion
Community Champion

@calerof 

it's not exactly my solution. Your _Price is calculated for current row context. The same is about _prevDate

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
calerof
Impactful Individual
Impactful Individual

@az38 I don't get your last comment. My formula is exactly as the one you posted, therefore I thought it was your solution. It doesn't get the correct result:

PriceChange.png

amitchandak
Super User
Super User

@Anonymous ,

As a new colum

maxx(filter(table, [date] =earlier([Date])-1),[SPX Price])

 

As a measure

This Day = CALCULATE(max([SPX Price]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
This Day = CALCULATE(max([SPX Price]), previousday('Date'[Date]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@Anonymous ,  

 

New columns if dates are not continous. In case date are continous the first formula I provided should be user. Earlier is powerful but costly. So should reduce the scope. 


last Date = maxx(filter(table, [date] <earlier([Date])-1),[[date]])
last Value = maxx(filter(table, [date] =earlier(last Date)),[SPX Price])

 

Measure Non continous 

Last Day Non Continous = CALCULATE(max([SPX Price]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
calerof
Impactful Individual
Impactful Individual

@amitchandak,

I have a problem with the last expression of the formula: "table[Date]", it doesn't fit, as the rest of the elemtents are calling the Date table and this last one is the date in the fact table.

F

 

@calerof , the correct version. Value replacement issue in my formula

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
calerof
Impactful Individual
Impactful Individual

@amitchandak 

Sorry, I checked it and didn't show the values on sparse dates, see:

LastDayNonContinous.png

calerof
Impactful Individual
Impactful Individual

Hi @amitchandak,

 

Your solution doesn't calculate the previous price if there is a gap between current date and the previous day of more than one day:

PreviousDay.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors