How to calculate Operating Margin
Operating margin is the share of revenue left after operating costs, before interest and tax. It shows the profitability of the core business.
Formula
Operating margin % = operating income ÷ revenue × 100, where operating income = revenue − COGS − operating expensesSQL query
This example assumes: ledger(period, category, amount) with category in 'revenue', 'cogs', 'opex'. It is written in PostgreSQL syntax; date functions differ slightly in MySQL, BigQuery and SQLite, and your column names will differ from these.
SELECT period,
(SUM(amount) FILTER (WHERE category = 'revenue')
- SUM(amount) FILTER (WHERE category = 'cogs')
- SUM(amount) FILTER (WHERE category = 'opex')) * 100.0
/ NULLIF(SUM(amount) FILTER (WHERE category = 'revenue'), 0) AS operating_margin_pct
FROM ledger
GROUP BY period
ORDER BY period;Common mistakes that make Operating Margin wrong
- Moving a cost between COGS and opex changes gross margin but not operating margin; know which you are looking at.
- Interest and tax belong below this line, so do not subtract them here.
- Capitalised costs (development, equipment) are not in opex until expensed.
Ask for Operating Margin in plain English
Instead of writing the query yourself, you can type the question. SchemaChat turns it into SQL against your connected database or uploaded file, runs it, and shows the SQL and the figures it used so you can check the answer before you share it. It does not replace your judgement about the definition: check that the query matches the formula your business uses.
- What is our operating margin by quarter?
- Which opex category grew fastest relative to revenue?