(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to calculate contribution margin per product in DAX: step by step

João Barros 20 de September de 2026 4 min read

Calculating Contribution Margin per product in DAX lets you know how much each product contributes to covering fixed costs and generating profit. This tutorial shows how to create clean measures that subtract variable costs, allocate fixed costs and display margin and margin % in the Power BI model.

Prerequisites

  • Power BI Desktop with Sales and Costs data (Sales table and Costs table)
  • Products table (Products) with ProductID and ProductName
  • Relationships configured: Sales[ProductID] → Products[ProductID]; Costs may be linked by ProductID or be a single fixed costs table
  • Basic knowledge of DAX: measures and filtering

Step 1: Understand the concept and prepare columns

Contribution Margin is typically Sales - Variable Costs. Then we can allocate fixed costs to products (by volume or by revenue). Confirm that the Sales table has Price and Quantity, and that there are columns or tables for variable costs per unit or per revenue.

Step 2: Create Revenue measure

First create a simple Revenue measure. This measure is the basis for other measures and must respect the filter context (product, date, etc.).

Revenue = SUMX(Sales, Sales[Price] * Sales[Quantity])

Step 3: Create Variable Cost measure

If variable costs exist per unit in Sales (e.g. VariableCostPerUnit), calculate the total by multiplying by Quantity. If it's a separate table, use a relationship or LOOKUPVALUE.

VariableCost = SUMX(Sales, Sales[VariableCostPerUnit] * Sales[Quantity])

Step 4: Calculate gross Contribution Margin

Subtract variable costs from revenue. Use DIVIDE when you need to calculate ratios later to avoid division by zero.

Contribution = [Revenue] - [VariableCost]

Step 5: Allocate Fixed Costs per product

There are several ways to allocate fixed costs. Here we give two examples: allocation by revenue (proportional) and allocation by units sold. The measures assume there is a measure TotalFixedCosts (global fixed costs value).

TotalFixedCosts = 50000   // example: monthly fixed amount

Step 6: Allocation by revenue (example)

This measure calculates the fraction of the product's revenue in the context over the total revenue and applies that fraction to fixed costs.

FixedCostAllocated_ByRevenue =
VAR TotalRevAllProducts = CALCULATE([Revenue], ALL(Products))
VAR ThisProductRev = [Revenue]
RETURN
IF(TotalRevAllProducts = 0, 0, ThisProductRev / TotalRevAllProducts * [TotalFixedCosts])

Step 7: Allocation by units (alternative example)

If you prefer to allocate by units sold, calculate the product's proportion of units versus total units.

TotalUnits = SUM(Sales[Quantity])

FixedCostAllocated_ByUnits =
VAR TotalUnitsAll = CALCULATE([TotalUnits], ALL(Products))
VAR ThisProductUnits = [TotalUnits]
RETURN
IF(TotalUnitsAll = 0, 0, ThisProductUnits / TotalUnitsAll * [TotalFixedCosts])

Step 8: Net Contribution Margin (after allocated fixed costs)

Now subtract the allocated fixed costs from the Contribution to obtain the final margin per product.

NetContribution_ByRevenueAlloc = [Contribution] - [FixedCostAllocated_ByRevenue]

NetContribution_ByUnitsAlloc = [Contribution] - [FixedCostAllocated_ByUnits]

Step 9: Calculate margin percentage

Percentage measures help compare products regardless of size. Use DIVIDE to avoid division by zero errors.

ContributionPct = DIVIDE([Contribution], [Revenue], 0)
NetContributionPct_ByRevenueAlloc = DIVIDE([NetContribution_ByRevenueAlloc], [Revenue], 0)

Verify the result

Create a table in Power BI with Products[ProductName] and the measures: Revenue, VariableCost, Contribution, FixedCostAllocated_ByRevenue (or ByUnits), NetContribution_..., ContributionPct. Check that totals make sense: sum of allocations should approximate TotalFixedCosts; products with zero revenue should not receive allocations; percentages should not produce errors.

Conclusion

With these measures you have a practical calculation of Contribution Margin per product and two ways to allocate fixed costs. Next steps: adjust the allocation (e.g.: by channel or by historical margin) and create visuals that show product-by-product and top contributors. Tip: test different allocation methods and compare the impact on margin to better understand the business.