Forum Discussion
Stock Portfolio Control ! Can i use the column that I am creating on the same calculation?
This is best done in DAX, but you are going to need to share some data, and explain your expected results. Median returns the value in the middle. Do you mean average?
How to get good help fast. Help us help you.
How To Ask A Technical Question If you Really Want An Answer
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.
- felipecarvalho5 years ago
Helper I
Hello Edhans, thanks for your reply.
I will try to time more details, but I also put a sample of the data on this GoogleSheets Spreadsheet so you can see the calculations that are being made :
https://docs.google.com/spreadsheets/d/1PFA5f9yeq8D02Hz4R6HVeFnemuQgYn5zuEidyzcfujY/edit?usp=sharing
In Brasil, in order to pay your taxes, you have to know your Cust of acquisition of your stocks.
I was not very accurate in the Translation. It is not the median or a simple average.I think the term that best describes what I am looking for is a weighted average of the costs ... but with a few rules.
Let's go to the example ;
Day 1 : Buy 100 of stock A for 10 . Cost= 10 * 100 = 1000 . Quantity =100.
Number of stock in portfolio =100
PM ( what I am looking) = Cost/Quantity = 10
Day 2 : Buy 200 of stock A for 20 . Cost =20*200 = 4000 . Quantity =200 .
Number of stock in portfolio =300
PM = (Previous Pm* Previous Number of stock) + (Cost ) / number of stock
(( 100 *100 ) +4000 ) / 300 = 16,666
Day 3
Sale of 200 of stock A. THE PM is not affected by sales. Now you have 100 stocks in your portfolio with a PM of 16,666 .
On this line, you can just repeat the Previous Pm or you can do the calculation:
PM = ( (Previous Pm* Previous Number of stock) + ( (- Quantity sold) * Previous Pm) /Number of stock
( (16.66 * 300) + (-200 *16,66)) /100
PM = 16,66
I hope it has all the details now. I think the link with the date makes it easier to follow.
I need to do this only in PowerQuery .The raw data has more rows with different stocks but they are in order ( first will appear all the operations of one stock before the next. I think with just this dataset is possible to help me.
Final question just to be sure. I cant refer to the same column that I am creating on the same step right?
Thank you very much.