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
Sachy123
Helper V
Helper V

Calculate daily returns

I have a data in the following format

 

DatePrice
15-12-20 100
14-12-20        50
13-12-20 20
12-12-2010

 

I would like to create a measure that can calculate daily returns with following formula

 

DatePriceReturns
15-12-20 100=(100-50)/50
14-12-20        50=(50-20)/20
13-12-20 20=(20-10)/10
12-12-20100

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Sachy123 , Try new column like

 

new column =
var _max = maxx(filter(table, [Date] < earlier([Date])),[Date])
return
[Price] - maxx(filter(table, [Date] = _max),[Price])


or

new column =
var _max = maxx(filter(table, [Date] < earlier([Date])),[Date])
var _1 = maxx(filter(table, [Date] = _max),[Price])
return
divide([Price] - _1,_1)

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

5 REPLIES 5
Sachy123
Helper V
Helper V

finally this one works like a charm

new column =
var _max = maxx(filter(table, [Date] < earlier([Date])),[Date])
var _1 = maxx(filter(table, [Date] = _max),[Price])
return
divide([Price] - _1,_1)

Anonymous
Not applicable

Hi  @Sachy123  ,

 

Sorry, this is my negligence. It should be to create a calculated column, not to create a measure. I made a mistake above

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sachy123
Helper V
Helper V

Hi guys, I get a red underline when I use the EARLIER function and there are no autosuggestions. 

amitchandak
Super User
Super User

@Sachy123 , Try new column like

 

new column =
var _max = maxx(filter(table, [Date] < earlier([Date])),[Date])
return
[Price] - maxx(filter(table, [Date] = _max),[Price])


or

new column =
var _max = maxx(filter(table, [Date] < earlier([Date])),[Date])
var _1 = maxx(filter(table, [Date] = _max),[Price])
return
divide([Price] - _1,_1)

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
Not applicable

Hi  @Sachy123  ,

Here are the steps you can follow:

1. Create calculated column.

 

Return =
var _datamax=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Date]<EARLIER('Table'[Date])))
var _price2=CALCULATE(MAX('Table'[Price]),FILTER('Table',[Date]=_datamax))
var _price1=CALCULATE(MAX('Table'[Price]))
var _final_price=(_price1-_price2)/_price2
return IF(_price2=0,BLANK(),_final_price)

 

2. Result

v-yangliu-msft_0-1608082912458.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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 Solution Authors
Top Kudoed Authors