Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Dynamically calculate multiple stock returns based on date slicer

Hi Power BI Community,

 

I recently came across an inspiring Power BI dashboard that provides a comprehensive analysis of individual stock performance within the S&P500. I'm eager to create something similar, but I'm facing challenges in automatically sorting the stock returns. To simplify the issue, I've prepared a sample setup that mirrors the problem.

 

The data is defined as follows: 

 

I've created a table with the following DAX code:

 

First_Last_Prices = 
SUMMARIZE (
    FILTER (
        ALL ( Sheet1 ),
        Sheet1[Date] >= MIN ( 'Sheet1'[Date].[Date])
            && Sheet1[Date] <= MAX ( Sheet1[Date].[Date] )
    ),
    Sheet1[ID],
    "First_Price", FIRSTNONBLANK ( Sheet1[PX_LAST], 1 ),
    "Last_Price", LASTNONBLANK ( Sheet1[PX_LAST], 1 )
)

 

Unfortunately the data in the table with the first and last price isnt changing when the dates in the slicers are changed.

 

 

The IDs are linked in model view.

 

 

I'm unable to attach the original file here, but you can access the Power BI file pbix and the accompanying data

 

Could you please provide guidance on improving the calculation of returns dynamically based on a date slicer?

 

Thank you in advance for your help!

3 Replies