How to calculate Return on Ad Spend (ROAS)
Return on ad spend is the revenue earned for every unit of money spent on advertising.
Formula
ROAS = revenue attributed to ads ÷ ad spendSQL query
This example assumes: ad_spend(campaign, day, cost), orders(id, campaign, ordered_at, total). It is written in PostgreSQL syntax; date functions differ slightly in MySQL, BigQuery and SQLite, and your column names will differ from these.
SELECT s.campaign,
SUM(s.cost) AS spend,
COALESCE(SUM(o.revenue), 0) AS revenue,
COALESCE(SUM(o.revenue), 0) / NULLIF(SUM(s.cost), 0) AS roas
FROM (SELECT campaign, SUM(cost) AS cost FROM ad_spend GROUP BY campaign) s
LEFT JOIN (SELECT campaign, SUM(total) AS revenue FROM orders GROUP BY campaign) o
USING (campaign)
GROUP BY s.campaign
ORDER BY roas DESC;Common mistakes that make Return on Ad Spend (ROAS) wrong
- Revenue is not profit: a ROAS of 3 can still lose money at a 30% margin.
- Joining two un-aggregated tables multiplies rows; aggregate each side first, as above.
- Attribution rules (last click vs any touch) change the revenue credited to a campaign.
Ask for Return on Ad Spend (ROAS) 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 ROAS by campaign for the last 30 days?
- Which campaigns spent more than they returned?