Ratio of sums
Define a KPI before writing DAX
A ratio measures a relationship between two quantities. Gross margin divides gross profit by revenue; contribution margin subtracts additional variable selling costs. A ratio of sums answers the overall business question; averaging displayed percentages instead weights each group equally. Use the isolated model in labs/business-kpis/README.md. All amounts are fictional USD, with costs stored as positive expenses. Three complete sales months (January–March 2025), monthly Periods, two Products, single-direction active relationships to both facts, no RLS. Examples are independent measure definitions unless labeled otherwise. Native DAX is not executed. The synthetic cost policy uses only COGS and variable selling cost; fixed overhead and tax are excluded. This is educational business arithmetic, not accounting advice.
Example 1 — Reconcile gross margin
Create these measures separately.
Revenue = SUM(Sales[RevenueUSD])COGS = SUM(Sales[COGSUSD])Gross Profit = [Revenue] - [COGS]Gross Margin = DIVIDE([Gross Profit], [Revenue])Use Products[ProductID] in a matrix. A: revenue 450, cost 270, profit 180, margin 40%. B: revenue 150, cost 120, profit 30, margin 20%. Total: revenue 600, cost 390, profit 210, margin 35%. The arithmetic mean of 40% and 20% is 30%, not the combined margin. DAX evaluates the measure again at total context. Percent formatting does not change the underlying numeric value.
Example 2 — Separate contribution from gross profit
Variable Selling Cost = SUM(Sales[VariableCostUSD])Contribution = [Gross Profit] - [Variable Selling Cost]Contribution Margin = DIVIDE([Contribution], [Revenue])A contributes 135 (30%); B contributes 20 (13.33%); overall 155 on revenue 600, or 25.83%. Variable selling cost totals 55. A contribution measure is not net profit. Keep the numerator and denominator under the same product and period filters. On March B the zero-value record gives zero revenue and contribution; margin is BLANK, not 0%.
Common mistakes — signs and totals
Subtract positive expenses once. If source costs are negative ledger entries, document and normalize their sign first. Do not use SUMX over displayed margin measures to force additive totals. A zero denominator has no defined margin; DIVIDE preserves that distinction. Missing source rows must be distinguished from certified zero activity; do not blanket COALESCE all metrics to zero.
Practice — Reconcile February
For February and each product, calculate revenue, gross profit, gross margin and contribution. Explain why the all-product margin differs from averaging the two product percentages. State which expenses are excluded. Check the result using the offline worksheet before optional Desktop verification.