How to calculate Cost per Mille (CPM)
CPM is the cost of showing an ad one thousand times, calculated from spend and impressions.
Formula
CPM = ad spend ÷ impressions × 1,000SQL query
This example assumes: ad_stats(day date, campaign text, spend numeric, impressions bigint). It is written in PostgreSQL syntax; date functions differ slightly in MySQL, BigQuery and SQLite, and your column names will differ from these.
SELECT campaign,
SUM(spend) AS spend,
SUM(impressions) AS impressions,
1000 * SUM(spend) / NULLIF(SUM(impressions), 0) AS cpm
FROM ad_stats
WHERE day >= CURRENT_DATE - 30
GROUP BY campaign
ORDER BY cpm DESC;Common mistakes that make Cost per Mille (CPM) wrong
- Average the daily CPMs and you get the wrong answer; divide total spend by total impressions instead.
- Platforms count impressions differently, so compare CPM within one platform.
- Spend in different currencies must be converted before it is summed.
Ask for Cost per Mille (CPM) 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 the CPM for each campaign over the last 30 days?
- Which campaigns have the highest cost per thousand impressions?