# Gross margin: Formula and dbt YAML | Silicon

URL: https://meetsilicon.com/metrics/gross-margin/

> Gross margin is the share of revenue left after subtracting the direct cost of delivering the product or service.

## Formula
Gross margin = (revenue − cost of goods sold) / revenue
## Why it matters
Gross margin shows how efficiently each sale turns into profit before operating costs, and limits how much you can spend to acquire customers.
## Common pitfalls
- Be consistent about what counts as cost of goods sold, especially hosting and support costs.
## Define it in dbt for Silicon
Add this to your model's YAML. Aggregate metrics sit under a column's meta.metrics; ratios are type: number metrics that reference other metrics. Rename models and columns to match your project.
schema.yml Copy
models:
- name: fct_revenue
meta:
metrics:
gross_margin:
type: number
sql: (${net_revenue} - ${cogs}) / NULLIF(${net_revenue}, 0)
format: percent
description: Share of revenue kept after direct costs
columns:
- name: net_amount
meta:
metrics:
net_revenue:
type: sum
description: Net revenue
- name: cogs_amount
meta:
metrics:
cogs:
type: sum
description: Cost of goods sold
Once it's defined, anyone can ask about gross margin in plain English and get an answer built on this definition. See the metrics reference for every option.
## Related
- Monthly recurring revenue (MRR) ->
- Annual recurring revenue (ARR) ->
- Net revenue ->
- Average order value (AOV) ->
- Semantic layer ->
## Tell us where your data lives today.
Book 30 minutes with the founder. Tell us where your data is today, and see Silicon running on sample data.
Talk to Sujay
30-minute call with the founder
