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

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: data.PNG

 

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.

 

report view.PNG

 

The IDs are linked in model view.

 

model view.PNG

 

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

Hi @Anonymous ,

 

Based on the information you provided, I understand that the problem you are experiencing is that First_Last_Prices does not change based on the slicer, you can follow these steps below:

 

1.Add ID table

vyifanwmsft_0-1704165002947.png

 

2.Create relationships

vyifanwmsft_1-1704165002950.png

 

3.Put table ID into Slicer

vyifanwmsft_2-1704165044732.png

 

 

Final output:

vyifanwmsft_3-1704165044734.png

 

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If I misunderstood you or it does not work, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Yifan Wang

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

Anonymous
Not applicable

Dear Yifan,

 

Thanks for your response! The values of first_price and last_price still dont respond to changes in the date slicer; it shows the data based on the data since inception ie the first and last date in the dataset. I've added a table with the PX_LAST data from sheet1 based on the last 3 years and the values dont correspond.

 

Also, I would like to show the first and last price based for all IDs ie the ID slicer should not affect the table with first_price and last price_price.

 

Capture2.PNG

 

Regards,

 

Webko

amitchandak
Super User
Super User

@Anonymous , You can follow approach given in the blog

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee884e

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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