Forum Discussion
andbeh
2 years agoNew Member
Calculate Contribution margin using Sales and Purchase tables
Hello, I'm trying to calculate the Contribution margin by taking the sales data from one table and the purchasing data from another. The Sales table contains the following columns: - OrderID ...
- Anonymous2 years ago
Hi andbeh ,
Based on your description, I created the following data model. Please refer to the following dax formula.
Result = CALCULATE ( MAX ( Sales[SalesPrice] ), FILTER ( ALL ( Sales ), Sales[ProductID] = MAX ( 'Product'[ProductID] ) && Sales[DateID] = MAX ( Sales[DateID] ) ) ) - CALCULATE ( MAX ( Purchasing[PurchasePrice] ), FILTER ( ALL ( Purchasing ), Purchasing[DateID] = MAX ( Purchasing[DateID] ) && Purchasing[ProductID] = MAX ( Purchasing[ProductID] ) ) )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
2 years agoSuper User
Hi,
Try this approach
- Create a Calendar Table with calculated column formulas for Year, Month name and Month number. Sort the Month name by the Month number.
- Create a relationship (Many to One and Single) from the Date column of both tables to the Date column of the Calendar Table
- Create a thir table with all unique ProductID entries.
- Create a relationship (Many to One and Single) from the ProductID column of both tables to the ID columns of the Product ID table create in step 3 above
- To any visual/filter/slicer, drag any date dimension from the Calendar Table and the Product ID column from the table create ni step 3 above
- Write these measures
S = sum(Sales[Salesprice])
P = sum(Purchases[Purchaseprice])
C = [S]-[P]
C % = divide([C],[S])
Hope this helps.