---
title: "Contribution margin by product | Oplema"
description: "Calculate contribution margin by product from order lines, fees and unit costs, and see why the best seller doesn't earn the most, using fictional data."
url: "https://oplema.com/use-cases/contribution-margin"
updated: "2026-11-04"
---

# Contribution margin by product

The best seller keeps 8p in every pound.

The company and data are fictional.

Contribution margin is what a sale keeps after the costs it causes: (net sales − variable costs) ÷ net sales.

Net sales are sales minus refunds. Variable costs come with each sale: product, shipping and card fees.

Tom Hale founded Tarn & Tin, which makes drinkware and sells it online and to trade accounts. He's picking one product to promote next month. Which one?

June net sales, after refunds, against what each product kept, best seller first.

- Insulated bottle *£3,914* **£327**
- Cooler bag *£3,735* **£1,720**
- Steel flask *£1,984* **£1,016**
- Travel cup *£1,782* **£1,101**
- Glass mug *£988* **£450**
- Lunch box *£840* **£562**
- Cotton tote *£540* **£417**
- Straw set *£372* **£292**

- Net sales
- Contribution

## Why the best seller is the wrong pick for now

June's sales report says promote the bottle, and nothing in it argues back. Ask three questions, though, and you get three winners.

June's shop sales, three ways.

| Question | Winner | Figure | What it tells you |
| --- | --- | --- | --- |
| Highest net sales | Insulated bottle | £3,914 | What's popular |
| Highest margin | Straw set | 78% | What each pound keeps |
| Most contribution | Cooler bag | £1,720 | What pays the bills |

Tom blames refunds first: the bottle has 73% of the shop's refunds. So he removes them all. The margin reaches 30% and it's still last. The real cost is the bottle itself, which takes 66% of its sales.

## How to calculate contribution margin by product

Tom builds a flow in [Strata](https://oplema.com/strata), Oplema's browser app for data prep, from three shop exports. Oplema's AI assistant, [Elara](https://oplema.com/elara), can help write the cost-sharing formula. Follow one order, ORD-5001, and its bottles.

1. ### Keep shipped orders.
   Canceled orders earn nothing.
   Filter
   ORD-5001 shipped, so it stays.
   | Orders | Count |
   | --- | --- |
   | Shipped | 70 |
   | Canceled | 2 |
2. ### Attach order costs and unit cost.
   Each line gets its order's shipping and card fees, and its product's cost.
   Join
   ORD-5001, the bottle line.
   | Shipping and fees on the order | Cost of one bottle |
   | --- | --- |
   | £16.90 | £25.00 |
3. ### Share order costs by line sales.
   An order can have two lines, so each takes its share of the shipping and fees.
   Formula
   The bottle line takes most of ORD-5001.
   | Line sales | Order sales | Share | Costs taken |
   | --- | --- | --- | --- |
   | £380 | £425 | 89% | £15.11 |
4. ### Total by product.
   Add up each product, then work out what it keeps.
   Summarize, Formula
   All Insulated bottle lines in June.
   | Net sales | Costs | Contribution | Margin |
   | --- | --- | --- | --- |
   | £3,914 | £3,587 | £327 | 8% |

## What would make the bottle the right pick?

The flow ends in a [Vista](https://oplema.com/vista) dashboard. Each setting changes the bottle only, at June's volume. Select each one and watch the red bar in Contribution by product.

[Skip the interactive dashboard](https://oplema.com/use-cases/contribution-margin#dashboard-end)

Loading the interactive dashboard. The figures below don't depend on it. The interactive dashboard didn't load. The figures below don't depend on it.

These are scenarios. Nobody has changed a refund or a supplier yet.

| Setting | Bottle contribution | Bottle margin | Earns most |
| --- | --- | --- | --- |
| Today | £327 | 8% | Cooler bag |
| Refunds halved | £916 | 20% | Cooler bag |
| Refunds halved, unit cost 10% lower | £1,251 | 28% | Cooler bag |
| Refunds halved, unit cost 25% lower | £1,753 | 39% | Insulated bottle |

Cutting refunds alone isn't enough. Even with refunds halved and cost 25% lower, it earns most but keeps the lowest margin.

## Tom holds the bottle and runs three tests

Each row is a test still to run.

| Who | Does what, and why |
| --- | --- |
| Buying | Tests a lower unit cost. |
| Support | Reads the refund reasons, since one product has 73% of refunds. |
| Marketing | Tries Cooler bag as the lead, since it keeps 46% and already sells. |

Now test your own best seller: take away its refunds. If it's still last, start with price and unit cost.

Who still owes for these sales? [Priya's call list](https://oplema.com/use-cases/ar-aging) says who to chase first.

How we built it

### Order lines

96 lines from your store.

Required columns: `order_id` `product_id` `quantity` `sales` `refunds`

### Orders

72 orders, with shipping and card fees.

Required columns: `order_id` `status` `shipping_cost` `payment_fees`

### Product costs

8 products, with unit costs.

Required columns: `product_id` `product` `unit_cost`

### See the steps run

Select the Formula block after the second Join: selling\_cost is the share worked out above.

[Skip the interactive flow](https://oplema.com/use-cases/contribution-margin#workflow-end)

Loading the interactive flow. The steps above don't depend on it. The interactive flow didn't load. The steps above don't depend on it.

Left to right: the three exports, the shipped filter, two joins, the cost formula, the product total, then the metrics the dashboard reads.

The formulas in this flow

| Column | Expression |
| --- | --- |
| Selling cost | `(shipping_cost + payment_fees) * sales / sum(sales) OVER (PARTITION BY order_id)` |
| Net sales | `sales - refunds` |
| Contribution | `round(net_sales - product_cost - selling_cost, 2)` |
| Margin | `round(100.0 * (net_sales - product_cost - selling_cost) / net_sales, 2)` |
| Refunds kept | `CASE WHEN product = 'Insulated bottle' AND params.fix >= 1 THEN round(refunds * 0.5, 2) ELSE 0 END` |
| Unit cost saved | `CASE WHEN product = 'Insulated bottle' THEN round(product_cost * CASE params.fix WHEN 2 THEN 0.10 WHEN 3 THEN 0.25 ELSE 0 END, 2) ELSE 0 END` |

### Choices and shortcuts

Margin is total over total. Averaging the product percentages gives 54% instead of 42%.

Sharing by line sales is a choice. Joining order costs straight onto lines charges an order's shipping once per line, and contribution falls to £5,558.

Refunded stock counts as lost, so a kept refund adds its full price. The settings hold volume and shipping as they were, and advertising and salaries aren't included. At the last setting the bottle's margin is 39%; the next lowest is 46%.

We left out 2 canceled orders worth £383. We wrote these patterns into the sample, so test the method on your own data.

### Definitions

**Net sales**

Sales minus refunds, excluding VAT.

**Contribution**

Net sales minus product cost, shipping and card fees.

**Margin**

Total contribution divided by total net sales.

**How it ties out**

Net sales of £14,155 minus £8,271.51 of costs leaves £5,883.49.

## FAQ

**How do you calculate contribution margin?**

Take net sales, subtract the costs that move with each sale, such as product cost, shipping and payment fees, then divide what is left by net sales. Across products, divide total by total.

**What is the difference between contribution margin and gross margin?**

Gross margin usually subtracts only the cost of the goods. Contribution margin also subtracts other costs that rise with each sale, such as shipping and fees, so it is often lower.

**Should I drop a low-margin product?**

Not from this alone. It may bring customers who buy other things, and that needs order history to test. Look at price, cost and refunds first.

**How should I share order-level costs?**

By line sales is the simple default. Weight or size can suit shipping better. The choice matters less than applying it the same way and stating it.

## Build this ranking from your exports

Rerun it when June becomes July. Local runs are free.

[Try it on your exports](https://oplema.com/editor?path=%2F%3Fopen%3Dstrata) [Read the docs](https://oplema.com/docs)
