Impression-Weighted Average CPM by Campaign Objective

Last updated: November 29, 2026

Quick Overview

Each row is an ad set's daily stats: objective, impressions, and CPM. Compute the correct average CPM per objective weighted by impressions, and show how it differs from the naive mean of CPMs.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Each row is an ad set's daily stats: objective, impressions, and CPM. Compute the correct average CPM per objective weighted by impressions, and show how it differs from the naive mean of CPMs.

Ads analytics questions at Meta often hide a weighting trap: averaging ratios across rows of very different size. This phone screen question checks that a candidate derives the weighted CPM as total spend over total impressions and can explain why the simple mean misleads advertisers.

What the Interviewer Expects
  • Recognize that averaging CPM per row over-weights small ad sets
  • Compute weighted CPM as sum(spend) / sum(impressions) * 1000
  • Derive spend from CPM and impressions if spend is not given
  • Exclude rows with zero impressions from the ratio
  • Present both numbers and explain the gap
Key Topics to Cover
weighted average
ratio metrics
CPM
groupby agg
Simpson's paradox
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • When would the naive mean ever be the right metric?
  • How would you compute a confidence interval for the weighted CPM?
  • How does this relate to Simpson's paradox when comparing objectives across countries?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Input ad_sets(objective, ad_set_id, impressions, cpm) where CPM is cost per thousand impressions. Spend is not stored, but spend = cpm * impressions / 1000. Rows with zero impressions have undefin...

Approach

Reconstruct spend per row, then aggregate per objective: total spend, total impressions, and the plain mean of cpm. Weighted CPM is 1000 * spend / impressions. This is identical to `np.average(cpm...


Submit Your Answer
Markdown supported