Attribute Orders to the Most Recent Promo Impression Within Seven Days
Last updated: November 29, 2026
Quick Overview
Given orders and promo impressions per customer, use pandas to attach each order to the latest promo the customer saw at or before the order time within the previous 7 days, then summarize attributed orders, customers and GOV per promo.
DoorDash
November 29, 20260
0
0 solved
Given orders and promo impressions per customer, use pandas to attach each order to the latest promo the customer saw at or before the order time within the previous 7 days, then summarize attributed orders, customers and GOV per promo.
DoorDash marketing runs many overlapping promos (new customer discounts, DashPass offers, merchant-funded deals), and last-touch attribution is a common first cut before incrementality tests. The take-home checks that you can do an as-of join correctly, by customer, with a lookback window, and that you explain what attribution can and cannot claim.
What the Interviewer Expects
- Use pd.merge_asof with by='customer_id', direction='backward' and a 7-day tolerance
- Sort both frames on the time key as merge_asof requires
- Keep unattributed orders in the output instead of dropping them
- Decide whether an impression at exactly the order time counts
- Explain that last-touch attribution is not incremental lift
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 split credit across all promos seen in the window instead of last touch?
- How would you implement this as-of join in SQL?
- Attributed GOV for promo A is high. Why is that not evidence the promo should be scaled?
- How would you avoid attributing an order to a promo the customer saw after they had already started checkout?
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
orders(order_id, customer_id, order_ts, subtotal) and impressions(customer_id, promo_id, impression_ts). Rule: last touch, at most 7 days before the order, impression at the same timestamp allowed...
Approach
This is exactly an as-of join. merge_asof walks both frames sorted by time, and for each order picks the latest impression whose time is at or before the order time, restricted to the same `customer...