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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Calculating variable stock returns

Hi,

I would like to make a visual of top 10 stocks differences, but with variable return horizon(ie, price_today - price 2 days before, or price_today - price n days before) where n is given by a measure and can be changed in a hover.

The problem is, my data has only three columns and looks like that (example for 2 symbols)

symboldateclose
T116/10/2022100
T216/10/202295
T115/10/202298
T215/10/202290
T114/10/202230
T214/10/202240

 

In this case i could change a hover and get 1-day diference (setting hover to 1), 2-day diference(setting hover to 2) ...

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.
Measure:

 

price n day = 
VAR _N = SELECTEDVALUE ( 'Table'[date] ) - 1
RETURN
    CALCULATE (SUM ( 'Table'[close] ),
        FILTER (ALL ( 'Table' ),
            [symbol] = SELECTEDVALUE ( 'Table'[symbol] )
                && [date] = _N ) )
Difference = IF([price n day]=BLANK(),0,SUM('Table'[close])-[price n day])

 

vzhangti_0-1669790289542.png

Change 1 to 2 to get the difference from the previous 2 days.

vzhangti_1-1669790411154.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

1 REPLY 1
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.
Measure:

 

price n day = 
VAR _N = SELECTEDVALUE ( 'Table'[date] ) - 1
RETURN
    CALCULATE (SUM ( 'Table'[close] ),
        FILTER (ALL ( 'Table' ),
            [symbol] = SELECTEDVALUE ( 'Table'[symbol] )
                && [date] = _N ) )
Difference = IF([price n day]=BLANK(),0,SUM('Table'[close])-[price n day])

 

vzhangti_0-1669790289542.png

Change 1 to 2 to get the difference from the previous 2 days.

vzhangti_1-1669790411154.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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