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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to calculate daily stock return using DAX formula?

sw40_0-1607747473239.png

Hi all, 

 

I want to calculate the daily return for this stock price (ignoring the weekend) by creating a new measure. May I know how should I do that by using DAX formula? I'm quite new to PowerBI. Thank you.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it.  Use this measure expression in a table visual with the date column from your stock table.  Replace Stock with your actual table name.

 

Change From Prev Day =
VAR thisvalue =
    MAX ( Stock[Close] )
VAR thisdate =
    MAX ( Stock[Date] )
VAR prevvalue =
    CALCULATE (
        LASTNONBLANKVALUE (
            Stock[Date],
            MAX ( Stock[Close] )
        ),
        FILTER (
            ALL ( Stock[Date] ),
            Stock[Date] < thisdate
        )
    )
RETURN
    DIVIDE (
        thisvalue - prevvalue,
        prevvalue
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it.  Use this measure expression in a table visual with the date column from your stock table.  Replace Stock with your actual table name.

 

Change From Prev Day =
VAR thisvalue =
    MAX ( Stock[Close] )
VAR thisdate =
    MAX ( Stock[Date] )
VAR prevvalue =
    CALCULATE (
        LASTNONBLANKVALUE (
            Stock[Date],
            MAX ( Stock[Close] )
        ),
        FILTER (
            ALL ( Stock[Date] ),
            Stock[Date] < thisdate
        )
    )
RETURN
    DIVIDE (
        thisvalue - prevvalue,
        prevvalue
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat Similar thing I need to do for Weekly and Monthly as well. Can you please help it is little urgent.

 

https://community.powerbi.com/t5/Desktop/stock-gainers-and-losers/td-p/3160077

 

@Greg_Deckler Can you please help me here?

@mahoneypat Any update on the above? Can you please help?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.