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
sa100
Helper I
Helper I

Separate profit calculation for each transaction

Hello,

I'd like to create a sample Profit table using the attached Sample Sales and Purchase Table. (see attached tables)

Calculation Criteria:

Each sales transaction requires an individual profit calculation.

Profit calculation will be based on the earliest purchase of the corresponding product.

If the quantities don't match, combine or partially combine the two purchase transactions.

I would greatly appreciate your assistance in solving this puzzle. Please note that the sample data includes only two products, but in a real scenario, there may be more than 100 products.

 

Purchase Table

CodeConfirmation NumberTrade DateUnit PriceQuantityBrokerageGSTPurchaseCost
KLM217151684Friday, 26 November 20210.371155518.141.814295.3
KLM217246886Friday, 3 December 20210.371345918.141.814999.78
KLM217735322Friday, 21 January 20220.4451119118.141.814999.95
KLM217741345Friday, 21 January 20220.431171718.141.815058.26
KLM217802780Tuesday, 25 January 20220.39764118.141.812999.94
KLM218207447Monday, 28 February 20220.505976418.141.814950.77
KLM218433664Thursday, 17 March 20220.5075567618.141.812900.52
SDA29254794Friday, 20 March 20200.1551653318.141.812582.57
SDA22Monday, 18 January 20210.36217600783.36
SDA213276727Friday, 29 January 20210.915217518.141.812010.08
SDA219474324Friday, 17 June 20222.06477518.141.819856.45
        
        

 

Sales Table

CodeConfirmation NumberTrade DateUnit PriceQuantityBrokerageGSTTotal Sale Price
KLM1742564922-Dec-210.422501418.141.8110485.93
KLM1773600421-Jan-220.441119118.141.814904.09
KLM1808187517-Mar-220.551000018.141.815480.05
KLM1809528318-Mar-220.54935818.141.815033.37
SDA142279297-Apr-211.161000018.141.8111580.05
SDA1433911916-Apr-211.295653022.682.278431.4
SDA1857343930-Mar-223.23435418.141.8114043.47

Profit Table

CodeConfirmation NumberTrade DateQuantityTotal Sale PricePurcahse Table Confirmation NumberPurchase Table QuantityPurchase CostOverall Purchase CostProfit/Loss
KLM1742564922-Dec-212501410485.93(217151684,217246886)(11555+13459)(4295.3+4999.78)9295.081190.85
KLM1773600421-Jan-22111914904.09217735322111914999.954999.95-95.86
KLM1808187517-Mar-22100005480.05(part of 217741345)10000(0.43*1000+18.14+1.81)4319.951160.1
KLM1809528318-Mar-2293585033.37(part of 217741345, 217802780)(1717+7641)(0.43*1717+0+0)+2999.943,738.251295.12
SDA142279297-Apr-211000011580.05part of 2925479410000(10000*0.155+18.14+1.81)1569.9510010.1
SDA1433911916-Apr-2165308431.4(part of 29254794)6530(6530*0.155+0+0)1012.157419.25
SDA1857343930-Mar-22435414043.47(part of 29254794,22,213276727)(3+2176+2175)(3*0.155+0+0)+783.36+2010.082793.9111249.56
3 REPLIES 3
sa100
Helper I
Helper I

Hi all, I'm eagerly anticipating guidance or a solution regarding my earlier post. thank you

sa100
Helper I
Helper I

Hi Albert @Anonymous 

Thanks for looking into this

Currently the relationship between Sales and Purchase table is many to many (code).

 

Otherway is to create a Master table by combining the Sales and Purchase table. Then we can have one to one relationship between Sales and Master; and between Purchase and Master (confirmation number)

Thank you

Regards

Sushil Arora

Anonymous
Not applicable

Hi @sa100 ,
I can understand what you mean, can you please provide the relationship between the sales table and the purchase table so that we can help you better

Best regards,

Albert He

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.