Cumulative Unique Reach and Average Frequency by Campaign Day
Last updated: November 29, 2026
Quick Overview
From raw ad impression logs, compute for each campaign and day the cumulative number of unique users reached so far, cumulative impressions, and average frequency (impressions per reached user) to date.
Meta
November 29, 20260
0
0 solved
From raw ad impression logs, compute for each campaign and day the cumulative number of unique users reached so far, cumulative impressions, and average frequency (impressions per reached user) to date.
Reach and frequency are headline metrics in Ads Manager, and cumulative unique reach is a known trap because distinct counts do not add across days. The interviewer wants the first-exposure trick: count each user only on the day they were first reached, then take a running sum.
What the Interviewer Expects
- Explains why summing daily unique users overcounts cumulative reach
- Finds each user's first impression day per campaign
- Running-sums new reach and impressions per campaign by day
- Divides cumulative impressions by cumulative reach for frequency
- Handles days with impressions but no newly reached users
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute rolling seven-day reach, which cannot use the first-exposure trick directly?
- At Meta scale, how would approximate distinct counting (HyperLogLog sketches) change this pipeline?
- How would you report reach for a campaign split across Facebook and Instagram without double counting cross-app users?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table: ad_impressions(campaign_id, user_id, impression_at). Duplicate rows are real repeat impressions. I report by impression date....
Approach
- First impression date per
(campaign_id, user_id); counting users by that date gives new reach per day. - Impressions per campaign per day.
- Left join new reach onto daily impressions (every ...