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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Greg_Deckler
Super User
Super User

@sjehanzeb What is your expected output? 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.