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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Nighthawk_
New Member

Calculating the Total of Current Value of Stock Portfolio

Hi guys,

 

I understand that my question has been asked 1000 times and I tried to apply some of the proposed solutions to my problem, but I guess I am just too stupid....

 

My basic data model:

Nighthawk__0-1647938732817.png

 

Table "Share Price" contains share price information on a daily basis:

Nighthawk__1-1647938840739.png

 

Table "Portfolio" contains the information of my portfolio:

Nighthawk__4-1647939221958.png

 

My problem now is, that the column total is wrong for "Current Value" and "Current Stock Price":

Nighthawk__3-1647939024067.png

 

I tried many different things, so far no luck. Here is my DAX for "Current Value"

 

Current Value = 
var Stock_Price = CALCULATE (
    CALCULATE (
        MAX ('Share Price'[fxYahoo.Close] ),
        FILTER (
            'Share Price',
            'Share Price'[fxYahoo.Date]
                = CALCULATE (
                    MAX ('Share Price'[fxYahoo.Date]),
                    ALLEXCEPT ('Share Price','Share Price'[Symbol] )
                )
        )
    )
)

var _value = SUM('Portfolio'[#Shares]) * Stock_Price
return
SUMX(Portfolio,if(Portfolio[Paid Price]>0,_value))

 

I am sure there is an easy fix to this, but I can't figure it out. Could you please lend me a hand?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Rename your existing Current Value measure to Current Value ( individual ) then create a new measure

Current Value = IF( ISINSCOPE( Portfolio[Symbol] ), [Current Value ( individual )],
SUMX( ADDCOLUMNS( SUMMARIZE( Portfolio, Portfolio[Symbol]), 
   "@value", CALCULATE( [Current Value ( individual )] ) ),
   [@value]
) )

Not sure what summarization you want for the current stock price, but you could replace the SUMX with AVERAGEX or whatever you need

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

Rename your existing Current Value measure to Current Value ( individual ) then create a new measure

Current Value = IF( ISINSCOPE( Portfolio[Symbol] ), [Current Value ( individual )],
SUMX( ADDCOLUMNS( SUMMARIZE( Portfolio, Portfolio[Symbol]), 
   "@value", CALCULATE( [Current Value ( individual )] ) ),
   [@value]
) )

Not sure what summarization you want for the current stock price, but you could replace the SUMX with AVERAGEX or whatever you need

Dear @johnt75 

 

Great, that worked. Thank you very much!!

 

For the "current Stock Price" I didn't want to have a total at all...

May I ask to elaborate a bit why this is working or please point me where I can get a better understanding?

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

Top Solution Authors