ETLMCPData Conveyance Works
Log in Start free
Guides

Compute CTR, CPC, CPA and ROAS from sums

Add up cost, clicks, impressions, conversions and value first, then divide: SUM(cost)/SUM(clicks) is your CPC, never AVG(cpc). Why, with SQL.

To get a correct CTR, CPC, CPM, CPA or ROAS for a week, a campaign or a whole account, add up the underlying counts first and divide once: SUM(cost) / SUM(clicks), never AVG(cpc). An average of daily ratios weights a quiet day the same as a busy one. When etlmcp groups rows with a transform, it does exactly this: it sums the base metrics and works the ratios out again from the totals.

Why the average of a ratio is wrong

Take two days of one campaign:

Day cost clicks cpc
Monday 100.00 10 10.00
Tuesday 10.00 100 0.10

AVG(cpc) says 5.05. You spent 110.00 for 110 clicks, so you paid 1.00 a click. Google Ads defines its average CPC the same way, as what all your clicks cost in total, split over how many clicks there were, and its CTR as clicks divided by impressions. Each of those is one total divided by another, so the only way to roll them up is to roll up the totals.

The same holds for every ratio in an etlmcp table:

Ratio Numerator Denominator
ctr clicks impressions
cpc cost clicks
cpm cost, times 1000 impressions
cpa cost conversions
roas conversion_value cost

Two units to watch. etlmcp's ctr is a fraction, so 0.05 is the 5% Google shows you; multiply by 100 for a percentage. ROAS here is value per unit of cost, so 5 means five in sales for each one spent; Google's Target ROAS page writes that as 500%, multiplying conv. value per cost by 100.

What etlmcp puts in each row

Every row etlmcp delivers carries impressions, clicks, cost, conversions and conversion_value, and next to them ctr, cpc, cpm and cpa. etlmcp works those four out itself for each row from that row's own counts, rather than keeping a ratio the platform reported. When a row's denominator is zero or missing, the ratio is left empty instead of failing. A plain row has no roas column.

These per-row ratios are right for the row they sit on and for nothing larger. In a daily campaign table, cpc is that campaign's CPC on that day. As soon as your report covers several days, campaigns or accounts, ignore the stored ratio columns and divide the sums.

Let a group rule do it

If you only need the rolled-up table, add a group rule to the pipeline. With the default agg of sum, it adds up the five base metrics within each group and then recomputes cpc, ctr, cpm and cpa from those totals, and it adds a roas column, conversion value over cost, wherever the group spent money. The ratios that arrived on the input rows are thrown away, never averaged. A group with no clicks gets no cpc, and likewise for the others.

{"op": "group", "by": ["campaign_name", "currency"]}

Keep agg at sum; avg averages the base metrics.

If you want a ratio of your own, put the derive rule after the group, so it divides the totals rather than each day's figures. A derive placed before the group is lost: the grouped rows keep only the key columns, the base metrics, the recomputed ratios and the platform extras. Division by zero in a derive expression gives an empty value, not an error.

Reach and user counts (reach, total_users, new_users) count each person once, so a group leaves them out rather than adding them up. Do the same in your own queries: do not sum them across days.

In SQL on the PostgreSQL table

The PostgreSQL destination creates the metric and ratio columns as double precision, so dividing two sums gives a decimal result, not a truncated whole number. Wrap each denominator in NULLIF(..., 0): PostgreSQL's NULLIF returns NULL when its two arguments are equal, so a campaign with no clicks gets an empty CPC instead of a division-by-zero error.

SELECT campaign_name,
       currency,
       SUM(cost) / NULLIF(SUM(clicks), 0)                   AS cpc,
       SUM(clicks) / NULLIF(SUM(impressions), 0)            AS ctr,
       SUM(cost) / NULLIF(SUM(impressions), 0) * 1000       AS cpm,
       SUM(cost) / NULLIF(SUM(conversions), 0)              AS cpa,
       SUM(conversion_value) / NULLIF(SUM(cost), 0)         AS roas
FROM public.ad_performance
WHERE date >= DATE '2026-11-01'
GROUP BY campaign_name, currency
ORDER BY campaign_name;

Here public.ad_performance stands for the schema and table you gave the destination. If several pipelines load the same table, add a filter on _etlmcp_pipeline_id so one pipeline's rows are not counted with another's.

Keep currency in the GROUP BY when accounts spend in different currencies: a sum of euros and dollars is not a cost. Convert first with an fx rule if you need one total.

In a BI tool or a spreadsheet

The same rule applies in Data Studio (formerly Looker Studio), Power BI, Tableau, Metabase or a spreadsheet pivot. Do not drag the stored cpc or ctr column into a chart with an average or a sum aggregation. Build a calculated field that divides the summed numerator by the summed denominator, such as total cost over total clicks, so every level of the chart, from one day to the whole year, divides its own totals.

When an AI agent queries the data

The query_data tool and the REST query return stored rows before any transform, so their ctr, cpc, cpm and cpa are per-row values. When you ask an agent for a campaign's CPC over a month, ask it to add up cost and clicks across the rows and divide, and check that it fetched every row in the range. Query data well has the rest.

Summing conversions across platforms raises a different problem, double counting, covered in summed platform conversions. For when a platform ROAS is the wrong number altogether, see MER vs platform ROAS.

Related

Sources

  1. Clickthrough rate (CTR): Definition - Google Ads Help — support.google.com, checked
  2. About Target ROAS bidding - Google Ads Help — support.google.com, checked
  3. Average cost-per-click (Avg. CPC): Definition - Google Ads Help — support.google.com, checked
  4. PostgreSQL: Documentation: 19: 9.19. Conditional Expressions — www.postgresql.org, checked