Metric

What is gross margin, and how do you measure it in Metabase?

What does a gross margin chart look like in Metabase?

Chart gross margin as a monthly line and watch the level, not just the direction: the steady climb toward 70% means cost of revenue is growing slower than revenue. A one-month dip like April's typically comes from a discrete cost event — an infrastructure migration double-running for a month — rather than pricing, so annotate it and confirm the line recovers.

Gross margin in Metabase: line chart of monthly gross margin percentage climbing toward 70%.
Gross margin as a Metabase card, built from modeled finance data. Figures are illustrative.

Definition

Gross margin is the share of revenue remaining after direct costs required to deliver the product or service. The hard part is not the arithmetic; it is agreeing which accounts and operational costs belong in revenue and cost of revenue.

Formula: Gross margin % = (revenue - cost of revenue) / revenue x 100

What data do you need?

  • Posted revenue journal lines
  • Posted cost-of-revenue journal lines
  • Maintained account classification
  • Product, segment, customer, and period dimensions
  • Credits, refunds, discounts, and revenue-recognition rules

SQL pattern

Monthly gross margin PostgreSQL
SELECT
  fiscal_month,
  SUM(CASE WHEN reporting_group = 'Revenue' THEN amount ELSE 0 END) AS revenue,
  SUM(CASE WHEN reporting_group = 'Cost of revenue' THEN amount ELSE 0 END) AS cost_of_revenue,
  ROUND(100.0 * (
    SUM(CASE WHEN reporting_group = 'Revenue' THEN amount ELSE 0 END)
    - SUM(CASE WHEN reporting_group = 'Cost of revenue' THEN amount ELSE 0 END)
  ) / NULLIF(SUM(CASE WHEN reporting_group = 'Revenue' THEN amount ELSE 0 END), 0), 2) AS gross_margin_pct
FROM modeled_gl
WHERE is_posted = TRUE
GROUP BY 1
ORDER BY 1;

Common pitfalls

Using payment volume as GAAP revenue. → Use the approved revenue-recognition or ledger source for financial gross margin.
Changing cost classification without restating history. → Version the account mapping and document whether historical periods were restated.
Averaging segment margin percentages. → Sum revenue and cost first, then calculate the aggregate margin.

Where does this metric apply?

This metric commonly uses data from NetSuite, Xero, QuickBooks, SAP, plus any reconciled warehouse or ledger models that provide the same business grain.

Dashboards

Integrations

Metrics

Analytics

FAQ

Is gross margin the same as contribution margin?
No. Contribution margin often subtracts additional variable costs; define both account mappings separately.
Should payment fees be in cost of revenue?
That is an accounting-policy decision. Apply the approved policy consistently and disclose it in the metric definition.