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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Daily Return [filtered stock price % change]

Hello,

can you please help me to find a custom formula or quick measure to calculate these daily retun of stocks price?

 

table:

 

IDOBS_DATE MM/DD/YYYYPRICEWANTED COLUM - RETURN daily % change
1000183873/2/202064.77-----
1000183873/3/202063.78-1.53%
1000183873/4/202068.056.69%
1000304183/2/202038.27-----
1000304183/3/202037.23-2.72%
1000304183/4/202038.754.08%

 

 Thank you!!

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create one measure as below:

Daily % change = var curdate=MAX('Daily Return'[OBS_DATE])
var predate=CALCULATE(MAX('Daily Return'[OBS_DATE]),'Daily Return'[OBS_DATE]<curdate)
var priceinPredate=CALCULATE(MAX('Daily Return'[PRICE]),'Daily Return'[OBS_DATE]=predate)
return IF(NOT(ISBLANK(priceinPredate)),DIVIDE(MAX('Daily Return'[PRICE])-priceinPredate,MAX('Daily Return'[PRICE])))

Daily change.JPG

Best Regards

Rena

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

View solution in original post

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create one measure as below:

Daily % change = var curdate=MAX('Daily Return'[OBS_DATE])
var predate=CALCULATE(MAX('Daily Return'[OBS_DATE]),'Daily Return'[OBS_DATE]<curdate)
var priceinPredate=CALCULATE(MAX('Daily Return'[PRICE]),'Daily Return'[OBS_DATE]=predate)
return IF(NOT(ISBLANK(priceinPredate)),DIVIDE(MAX('Daily Return'[PRICE])-priceinPredate,MAX('Daily Return'[PRICE])))

Daily change.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-yiruan-msft Rena, 

 

Thank you for the support! This is exactly what I was looking for.

If possible, could you please tell how would I add this daily % change as a custom colum instead of a measure? Will this have any impact on performaces?

 

Much appreciate, regards,

Luca.

Hi @Anonymous ,

The biggest difference between calculated column and measure is that calculated column is stored in memory, consuming a certain amount of memory. It will affect the performance of query calculations when the amount of data is large. You can find the details in this post.

You can also create one calculated column as below base on your scenario:

 

Prevprice = var a ='Daily Return'[OBS_DATE]
var b= CALCULATE(MAX('Daily Return'[OBS_DATE]),FILTER('Daily Return','Daily Return'[ID]=EARLIER('Daily Return'[ID])&&'Daily Return'[OBS_DATE]<a)) 
var c= CALCULATE(max('Daily Return'[PRICE]),FILTER('Daily Return','Daily Return'[ID]=EARLIER('Daily Return'[ID])&&'Daily Return'[OBS_DATE]=b))
return IF(NOT(ISBLANK(c)),DIVIDE('Daily Return'[PRICE]-c,'Daily Return'[PRICE]))

 

calculated column.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
camargos88
Community Champion
Community Champion

@Anonymous ,

 

You can try this measure:

 

Measure =
VAR _lastday = CALCULATE(PREVIOUSDAY('Table'[OBS_DATE]))
VAR _ID = CALCULATE(MIN('Table'[ID]); FILTER(ALL('Table'); 'Table'[OBS_DATE] = _lastday))
VAR _lastPrice = CALCULATE(SUM('Table'[PRICE]); FILTER(ALL('Table'); 'Table'[OBS_DATE] = _lastday && 'Table'[ID] = _ID))
RETURN DIVIDE(SUM('Table'[PRICE]) - _lastPrice; _lastPrice; 0)
 
However you have more than 1 date, maybe you have the stock name ??? If yes, you can use this:
Measure =
VAR _lastday = CALCULATE(PREVIOUSDAY('Table'[OBS_DATE]))
VAR _lastPrice = CALCULATE(SUM('Table'[PRICE]); FILTER(ALLEXCEPT('Table'; ___STOCKNAME___); 'Table'[OBS_DATE] = _lastday))
RETURN DIVIDE(SUM('Table'[PRICE]) - _lastPrice; _lastPrice; 0)
 
With this you can get the last date by stock name.
 
Ricardo
 
 


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors