How to calculate Net Profit Margin

Net profit margin is the percentage of revenue that remains as profit after all expenses, interest and taxes.

Formula

Net margin % = net income ÷ revenue × 100

SQL query

This example assumes: ledger(period, account_type, amount) where account_type is 'revenue' or 'expense' and amounts are positive. 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 account_type = 'revenue') AS revenue,
       SUM(amount) FILTER (WHERE account_type = 'revenue')
     - SUM(amount) FILTER (WHERE account_type = 'expense') AS net_income,
       (SUM(amount) FILTER (WHERE account_type = 'revenue')
      - SUM(amount) FILTER (WHERE account_type = 'expense')) * 100.0
         / NULLIF(SUM(amount) FILTER (WHERE account_type = 'revenue'), 0) AS net_margin_pct
FROM ledger
GROUP BY period
ORDER BY period;

Common mistakes that make Net Profit Margin wrong

  • One-off gains or write-offs make a single period unrepresentative.
  • Revenue and expenses must be on the same accounting basis (accrual vs cash).
  • Intercompany transactions inflate both sides if not eliminated.

Ask for Net Profit 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 was our net profit margin each quarter?
  • How much did one-off items change net margin last quarter?

Frequently asked questions

What is Net Profit Margin?
Net profit margin is the percentage of revenue that remains as profit after all expenses, interest and taxes.
How do you calculate Net Profit Margin?
Net margin % = net income ÷ revenue × 100. The SQL example on this page shows the same calculation against a simple table.
What commonly goes wrong when calculating Net Profit Margin?
One-off gains or write-offs make a single period unrepresentative.