Margin analysis: by product, customer and mix, and how AI keeps it current
Margin analysis measures what each product, customer, channel, and order earns after costs, and why that changed.

What margin analysis is
Margin is what a sale leaves after the costs that come with the sale. Margin analysis asks where that margin comes from. The analysis finds which products, customers, channels, and orders produce margin, which ones dilute margin, and what changed between two periods. The Business Development Bank of Canada (BDC) calculates gross margin as gross profit divided by revenue. BDC defines gross margin as “the portion of a company’s revenue left over after direct costs are subtracted.”
The term has a second meaning for SAP users. In SAP S/4HANA, Margin Analysis is the name of the account-based profitability module. SAP says that the module “helps to ensure that Management Accounting and Financial Accounting (FI) are reconciled at the account level at all times.”
This guide uses the general sense: an analysis of a company’s own sales and cost data, whatever the ERP.
The questions that margin analysis answers are practical:
- Which customers make the least after discounts, rebates, and freight?
- Which product families grow sales without growing profit?
- Did last year’s price increase hold, or did discounts take it back?
- How much margin goes to freight on small orders?
The measures behind margin analysis
Five measures cover most of the work. The table shows how to calculate each measure and what each measure tells you.
| Measure | How to calculate the measure | What the measure tells you |
|---|---|---|
| Gross margin | (Revenue − cost of goods sold) ÷ revenue | How much of each sales dollar is left after the direct cost of the goods |
| Contribution margin | Price − variable costs, per unit or in total | What each sale adds toward fixed costs and profit |
| Contribution margin ratio | Contribution margin per unit ÷ price per unit | The share of each sales dollar that covers fixed costs |
| Pocket margin | Price after every discount, rebate, early-payment discount, and freight cost, minus cost | What you keep from one customer or one order |
| Markup | (Price − cost) ÷ cost | The percentage added to cost to set a price |
OpenStax’s managerial accounting textbook defines contribution margin as “the amount by which a product’s selling price exceeds its total variable cost per unit.”
The same section explains why the measure matters. Knowing how each product contributes “allows managers to make decisions such as which product lines they should expand or which might be discontinued.”
Gross margin is the figure on the income statement. For a decision about one product or one customer, use contribution margin. Fixed costs such as rent do not change when one order is won or lost.
Margin and markup describe the same dollars over different bases. A part that costs $80 and sells for $100 has a markup of 25% on cost and a margin of 20% on price. To convert, divide the markup by one plus the markup: 0.25 ÷ 1.25 = 0.20. A sales team that quotes from a markup table can disagree about the same order with a finance team that reports margin. For setting prices from cost, see cost-plus pricing.
Four ways to cut margin
The totals on an income statement hide where margin is made. The same data, cut four ways, answers four different questions.
By product
Margin by product shows which items carry the business, whether you measure margin by SKU (stock-keeping unit), by product family, or by job. The weak point is cost. A standard cost set two years ago, or overhead spread evenly across every item, makes low-volume items look better than they are. Plante Moran, an accounting and advisory firm, describes one such cost error in The art of SKU rationalization. When costing leaves out changeover time, high-volume parts end up subsidizing the changeovers that low-volume parts cause. In a plant, product margin needs the real setup time and scrap of each item. In a distribution business, product margin needs the landed cost: the purchase price plus freight, duty, and handling.
By customer
A distributor sees margin by customer with a tool that matches every discount, rebate, freight bill, and return to the customer behind the cost. Two customers can buy the same item at the same list price and leave different margins. The difference sits in discounts, rebates, payment terms, freight, returns, order size, and the staff time that each account takes. McKinsey calls the path from list price to what a business actually keeps the pocket price waterfall. In the McKinsey example of a lighting supplier, discounts shown on the invoice put average invoice prices 32.8% below list. Deductions that never appeared on the invoice took another 16.3 percentage points. Those deductions included prompt-payment discounts, cooperative advertising, volume rebates, and freight. The average pocket price ended up at about half the list price.
Most of those deductions live in the general ledger, in rebate spreadsheets, and in freight bills, away from the invoice line. Each deduction has to be matched back to the customer who caused that deduction.
By channel
A channel is a route to the customer: direct sales, distributors, retailers, an online store, or quotes for custom work. Each channel has a different price level and a different cost to serve. Take a food producer that sells the same product to a grocery chain and to food service. The producer can compare the two channels after promotion spending, pack sizes, and freight. Margin by channel shows whether growth in one route is diluting the total.
By mix
Mix is the share of each product, customer, or channel in total sales. A margin mix analysis measures how a shift in that share changes total margin. When the mix shifts toward lower-margin items, total margin can fall even when every price holds and sales grow. Product mix and inventory mix are linked. The stock that you hold limits what you can sell, and the margin on that stock decides what the stock earns. The following example separates the mix effect from price, volume, and cost.
Price, volume, and mix: a worked example
A price, volume, and mix analysis, often called a PVM bridge, splits the change in contribution between two periods into the parts behind the change. The ACCA, a professional accounting body, explains the method in an examiner’s report for the ACCA Performance Management exam. The same method compares this year with last year. Under marginal costing, which counts only variable costs in product cost, the variances are valued at standard contribution. The report says that the mix and quantity variances “are just a further analysis of the sales volume variance.”
Here a distributor sells two product lines. The numbers are made up for this example.
| Line A, standard fittings | Line B, custom assemblies | |
|---|---|---|
| Units sold last year | 12,000 | 4,000 |
| Price last year | $20.00 | $50.00 |
| Variable cost per unit last year | $14.00 | $30.00 |
| Units sold this year | 16,000 | 4,000 |
| Price this year | $19.50 | $51.00 |
| Variable cost per unit this year | $14.25 | $30.50 |
Revenue rose from $440,000 to $516,000, or 17%, and units rose 25%. Contribution rose only $14,000, from $152,000 to $166,000, and the contribution margin fell from 34.5% to 32.2% of sales. The bridge shows why.
| Effect | How the effect is calculated | Change in contribution |
|---|---|---|
| Volume at last year’s mix | 4,000 more units × last year’s average contribution of $9.50 a unit | +$38,000 |
| Mix | At last year’s 75/25 split, 20,000 units would have been 15,000 of A and 5,000 of B. The year sold 1,000 more A at $6.00 and 1,000 fewer B at $20.00 | −$14,000 |
| Price | 16,000 × −$0.50 on A, plus 4,000 × $1.00 on B | −$4,000 |
| Cost | 16,000 × −$0.25 on A, plus 4,000 × −$0.50 on B | −$6,000 |
| Total | The sum of the four effects | +$14,000 |
The mix line is the largest negative. Price and cost together take $10,000, and the shift toward Line A, the lower-margin line, takes $14,000. The next conversation is about which products the sales team promoted, as well as the discount on Line A.
For two lines, this analysis takes an afternoon in a spreadsheet. For 3,000 items and 400 customers, the analysis needs software that runs the bridge again every month.
How margin analysis is done by hand
Margin by order is often unknown until month end, because freight, rebates, and credit notes post to the ledger after the invoice. In most smaller companies, someone in finance builds the analysis in a spreadsheet a few times a year:
- Export invoice lines from the ERP: date, customer, item, quantity, and price.
- Look up a cost for each item, usually the standard cost on the item card.
- Spread freight, rebates, and returns from the general ledger as a percentage, because those costs are not on the invoice line.
- Build pivot tables by product, customer, and region.
- Explain the change from last year in a slide.
Each step has a weak point. Standard costs drift away from what the business actually pays. Freight and rebates spread as a flat percentage hide the customers that cost the most to serve. Credit notes and returns post later and often land in the wrong month. By the time the analysis is finished, the quarter has moved on, too late to change that quarter’s prices.
What AI changes in margin analysis
The arithmetic stays the same. Software takes over the work around the arithmetic, which is most of the effort.
Software rebuilds the analysis every week
A scheduled job pulls the week’s invoice lines, credit notes, and receipts from the ERP. The job matches each sale to the cost of the goods behind the sale, and recalculates margin by product, customer, and channel. Keep the calculations in code or in SQL, the query language of databases, because code gives the same answer every time. Use a language model to read documents and explain results, and keep the model away from the sums.
Models read the documents that hold the real costs
Freight bills, supplier invoices, rebate agreements, and customs entries often arrive as PDFs or emails. Language and vision models read these documents into structured data. The real freight on each shipment and the landed cost of each receipt can then be matched to the sale.
A model explains the change in plain language
After the bridge is calculated, a language model can draft the commentary. The commentary covers which customers moved, which products drove the mix effect, and which price changes held. Link each sentence to the rows behind the sentence, so that a controller can check each claim. Some ERPs add a plain-language layer on top of their own data. In Business Central, Microsoft’s analysis assist is a preview feature for analyzing list data. The feature translates plain instructions into “the corresponding rows, columns, filters, and aggregations,” in Microsoft’s words. One instruction that the feature accepts is “sort on quantity from smallest to largest,” and another is “show average cost per category.”
Rules flag what needs a decision
Rules and models can watch for the patterns that a person would act on. Examples include a customer whose margin fell three months in a row, or an item sold below the item’s floor price. Others are a supplier cost increase that never reached the price list, and a customer about to reach a rebate tier. Each flag goes to a named person who decides what to do.
Test a change before you make it
With margin by product and customer in one place, you can test a change against last year’s data. The change might be a 2% increase on one product family, a minimum order charge, or dropping a slow line. In a 2003 article, McKinsey worked through the average income statement of an S&P 1500 company. The effect of a 1% price rise came out nearly 50% larger than the effect of a 1% cut in variable costs. With volumes stable, McKinsey found that a 1% price rise “would generate an 8 percent increase in operating profits.”
The data margin analysis needs
Everything comes from systems that the business already runs: the ERP, the accounting system, and a few spreadsheets.
| Data | Where the data usually lives | What the data adds |
|---|---|---|
| Invoice lines and credit notes | ERP sales module | Revenue by item, customer, date, and price |
| Item cost: standard cost, purchase receipts, bills of materials, and routings | ERP inventory, purchasing, and manufacturing | The cost of goods sold for each item |
| Freight, duty, and handling | Freight bills, customs entries, general ledger | Landed cost and cost to serve |
| Rebates, discounts, and payment terms | Customer agreements, spreadsheets, general ledger | The pocket price for each customer |
| Returns and warranty claims | ERP, service records | Margin lost after the sale |
| Customer, channel, and sales rep | Customer master, CRM (customer relationship management system) | The groupings for the analysis |
| General ledger | Accounting system | The totals that the analysis must tie back to |
Test the result against the books first. The gross margin that the analysis reports for last year must match the income statement, with any difference explained line by line. Fix any gap before anyone uses the numbers for a decision. For getting data out of the ERP that you run, see AI for ERP.
How to start small
- Pick one question. For example: which 20 customers made the least contribution last year after freight and rebates?
- Pull 24 months of data for one product family or one region: invoice lines, credit notes, receipts, and the related ledger entries.
- Tie the data to the general ledger until every difference is explained.
- Add the costs that the invoice line misses, starting with freight and rebates.
- Build the price, volume, and mix bridge for the last two years, and check the bridge with your controller.
- Run the bridge every month, with a short written explanation that a person reviews before the explanation goes out.
Which costs in your margin are spread by a flat percentage? Those lines are where the analysis is most likely to be wrong, and where real data changes the answer most.
Find out what your margin data can show
Tell us which ERP and accounting system you run, and which margin question you cannot answer. We will tell you what your data can support.
Risks and limits
- Allocations are judgments. Spreading warehouse cost across customers by order lines or by weight gives different answers. Write the rule down and keep the rule stable, so that a change in margin comes from the business, not from the method.
- Stale standard costs mislead. If standard costs are out of date, margin by product is wrong before any AI touches the numbers. Compare standard costs with actual receipts and production costs first.
- A low-margin customer can still be worth keeping. A customer who fills spare machine time or buys a whole range can be worth more than the per-order view suggests. Decisions about customers stay with people.
- Language models make mistakes with numbers. A model can state a wrong figure with confidence. Keep calculations in code, show the source rows for every figure, and test the explanations against cases that you already know.
- Sales and cost data is confidential. Decide where the data is processed before you connect any tool.
How ThriveAI helps
ThriveAI, an AI engineering company in Ottawa, builds private AI systems on a company’s own data for businesses that make, move, or sell physical goods. For margins, the system joins the sales lines, costs, rebates, and freight that your ERP and accounting system already hold. Margin by product, customer, and channel then stays current. The system flags the lines whose margin moved, for a named person to review. Every answer shows the record behind the answer.
ThriveAI’s systems read your ERP and accounting system as they are, and every connection is read-only. Your company has a copy of the data reserved for your team. ThriveAI hosts that copy, or you host the copy on your own servers. You choose a model where the copy is hosted, or a hosted model under a written zero data retention agreement. A hosted model may process requests in another country. Derik Lawlis, the founder, leads every project and stays close to the build. For more about the company, see About ThriveAI.