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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
sjehanzeb
Resolver I
Resolver I

Calculating earlier values

my data is obtained from investment in stock exchange. i need to calculate profit on each selling/settlement.


Sample Data

DateScripActivity TypeNosAmountExpected Output
PROFIT / LOSS (Avg Rate)

Calculated Column

SHARE ON HAND

1-Jan-20PPPBUY100012000  
2-Jan-20PPPBUY200023000  
3-Jan-20DDDBUY1000600  
3-Jan-20PPPSELL250030000833.33 *1 
4-Jan-20PPPBUY5006000  
5-Jan-20DDDSELL1000400-200 *2 
5-Jan-20PPPSELL100012000250*3 

 

Formula = Sales Amount - (Average Rate of Purchase of stock on hand x No. of Share sold)

*1    33000 -  ((12000+23000)/3000 * 2500) = 833.33

*2     400 - (600/1000 * 1000)  =  -200

*3     12000 -      ((23000/2000 * 500) + (6000/500 *500))/1000) * 1000

 

I need to calculate profit/loss on every sell. either through average or fifo method.  

 

Probable solution is to have a caculated column to calculate no. of shares on hand on each date, from there we can calculate cost of purchase of each instance. 

 

 

2 REPLIES 2
amitchandak
Super User
Super User

@sjehanzeb , Try as a new column if this can help

column =
var _amt = sumx(filter(Table,[Script] =earlier([Script]) , [Date] <earlier([Date])),if([Activity] = "Buy",[Amount] ,=-1*[Amount]))
var _Nos = sumx(filter(Table,[Script] =earlier([Script]) , [Date] <earlier([Date])),if([Activity] = "Buy",[Nos] ,=-1*[Nos]))
return
[Amount] - (Divide(_amt,_Nos)*[Nos])

Greg_Deckler
Super User
Super User

@sjehanzeb What is your expected output? 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.