Margin analysis: by product, customer and mix, and how AI keeps it current
Margin analysis is the work of finding out how much each product, customer, channel and order earns after the costs that come with it, and why that changed since last year. It rests on two measures, gross margin and contribution margin, and on one technique that splits a change in profit into price, volume, mix and cost. Most smaller businesses do it in a spreadsheet a few times a year. AI can rebuild it every week from the ERP and the accounting system, with each figure traced to its invoice line. This guide covers the measures, four ways to cut the numbers, a worked example and how to start.

What margin analysis is
Margin is what a sale leaves after the costs that come with it. Margin analysis asks where that margin comes from: which products, customers, channels and orders produce it, which ones dilute it, and what changed between two periods. The Business Development Bank of Canada (BDC) defines gross margin as “the portion of a company’s revenue left over after direct costs are subtracted,” calculated as gross profit divided by revenue.
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 it “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: the analysis any business can run on its own sales and cost data, whatever its ERP.
The questions it 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 each one is calculated and what it tells you.
| Measure | How to calculate it | What it 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 it 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, because 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 and a finance team that reports margin can end up disagreeing about the same order. Cost-plus pricing covers setting prices from cost.
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 it by SKU, 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, warns in The art of SKU rationalization that 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, it needs the landed cost: the purchase price plus freight, duty and handling. SKU rationalization covers what to do with the items at the bottom of the list.
By customer
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 each account takes. McKinsey calls the path from list price to what a business actually keeps the pocket price waterfall. In its 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, such as prompt-payment discounts, cooperative advertising, volume rebates and freight, took another 16.3 percentage points. 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. Margin by customer needs every one of them matched back to the customer who caused it.
By channel
A channel is a route to the customer: direct sales, distributors, retailers, an online store, or quotes for custom work. Each has its own price level and its own cost to serve. A food producer that sells the same product to a grocery chain and to food service can compare the two 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. 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 you hold limits what you can sell, and the margin on that stock decides what it earns. Inventory optimization covers the stock side. The example below 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 that caused it. The ACCA, a professional accounting body, explains the method in an examiner’s report for its Performance Management exam. The mix and quantity variances, it says, “are just a further analysis of the sales volume variance,” valued at standard contribution when you use marginal costing. The same method compares this year with last year.
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 it 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. That points the next conversation at which products the sales team promoted, as well as at the discount on Line A.
For two lines, this takes an afternoon in a spreadsheet. For 3,000 items and 400 customers, it needs software, and it needs to run again every month.
How margin analysis is done by hand
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 they 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, and the results come 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 it, which is most of the effort.
It rebuilds the analysis every week
A scheduled job pulls the week’s invoice lines, credit notes and receipts from the ERP, matches each sale to the cost of the goods behind it, and recalculates margin by product, customer and channel. Keep the calculations in SQL or code, which give the same answer every time. Use a language model to read documents and explain results, and keep it away from the sums.
It reads 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 them into structured data, so the real freight on each shipment and the landed cost of each receipt can be matched to the sale. AI invoice processing and text extraction from images cover how to test that reading on your own documents.
It explains the change in plain language
After the bridge is calculated, a language model can draft the commentary: which customers moved, which products drove the mix effect and which price changes held. Link each sentence to the rows behind it, so a controller can check it. 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. It can translate instructions like “sort on quantity from smallest to largest” or “show average cost per category” into “the corresponding rows, columns, filters, and aggregations.”
It flags what needs a decision
Rules and models can watch for the patterns a person would act on: a customer whose margin fell three months in a row, an item sold below its floor price, a supplier cost increase that never reached the price list, or a customer about to reach a rebate tier. Each flag goes to a named person who decides what to do. Human in the loop covers designing that review.
It tests 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: 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. It found that a 1% price rise, with volumes stable, “would generate an 8 percent increase in operating profits,” nearly 50% more than the effect of a 1% cut in variable costs. Price optimization and pricing intelligence cover setting prices from cost, demand and the market, and AI financial modeling covers building the financial model from the ERP and the books.
The data margin analysis needs
Everything comes from systems the business already runs: the ERP, the accounting system and a few spreadsheets.
| Data | Where it usually lives | What it 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 | The groupings for the analysis |
| General ledger | Accounting system | The totals the analysis must tie back to |
Test the result against the books first. The gross margin the analysis reports for last year must match the income statement, with any difference explained line by line. Fix that before anyone uses the numbers for a decision. AI for ERP covers getting data out of the ERP you run, and legacy ERP automation covers older systems installed on your own server.
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 it to the general ledger until every difference is explained.
- Add the costs the invoice line misses, starting with freight and rebates.
- Build the price, volume and mix bridge for the last two years and check it with your controller.
- Run it every month, with a short written explanation that a person reviews before it goes out.
Which costs in our margin today 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 Derik which ERP and accounting system you run and which margin question you cannot answer today. He will tell you what your data can support.
Start a conversationRisks 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 it stable, so that a change in margin comes from the business rather than from the method.
- Stale standard costs mislead. If standards are out of date, margin by product is wrong before any AI touches it. Compare standards 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. They can state a wrong figure with confidence. Keep calculations in code, show the source rows for every figure, and test the explanations against cases you already know. AI evals covers that testing, and RAG covers answers that cite their sources.
- Sales and cost data is confidential. Decide where it is processed before you connect any tool. Private AI for business lists the questions to put to a vendor.
How ThriveAI helps
ThriveAI is an AI engineering company in Ottawa that builds private AI systems on a company’s own data, for businesses that make, move or sell physical goods. For margins, that means joining the sales lines, costs, rebates and freight your ERP and accounting system already hold, so margin by product, customer and channel stays current, and flagging the lines whose margin moved for a named person to review. Every answer shows where it came from.
ThriveAI’s systems read your ERP and accounting system as they are, and every connection only reads data. They are designed to keep each client’s data on its own server in Canada. You choose a model on that server or a hosted model under a written zero data retention agreement, and a hosted model may process requests outside Canada. Derik Lawlis, the founder, leads every project and stays close to the build. About ThriveAI covers the company.