Monthly Lead Cohort Funnel From Lifecycle Stage History

Last updated: November 29, 2026

Quick Overview

Given a table of contact lifecycle stage changes (contact_id, stage, entered_at), compute for each monthly cohort of new leads how many reached MQL, SQL and customer within 90 days of becoming a lead, along with the conversion rates.

HubSpot
Data Manipulation (SQL/Python)
Data Scientist
HubSpot
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a table of contact lifecycle stage changes (contact_id, stage, entered_at), compute for each monthly cohort of new leads how many reached MQL, SQL and customer within 90 days of becoming a lead, along with the conversion rates.

Lifecycle stages (lead, MQL, SQL, opportunity, customer) are the backbone of HubSpot's marketing and sales reporting, and customers constantly ask how their funnel converts. The interviewer is checking whether you handle messy stage histories (skipped stages, regressions, repeats) and define the cohort window precisely.

What the Interviewer Expects
  • Clarifies how to treat skipped stages, repeated entries and stage regressions
  • Anchors each contact to the first time it became a lead
  • Applies the 90-day window relative to the lead date, not the calendar month
  • Counts a later stage as implying earlier ones when stages are skipped
  • Guards against division by zero and excludes contacts with no lead entry
Key Topics to Cover
cohort analysis
conditional aggregation
funnel metrics
date windows
SQL
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
  • Recent cohorts have not had 90 days to mature. How do you report them?
  • How would you compute median time from lead to customer per cohort?
  • How would you break this down by original traffic source?
  • How would you compute this efficiently across 200k portals?
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

Table lifecycle_stage_history(contact_id, portal_id, stage, entered_at), one row per stage entry. Stages may be skipped (lead straight to customer), repeated, or regress (MQL back to lead). I will a...

Approach
  1. Pivot each contact's history to the first timestamp per stage with conditional MIN.
  2. Build flags per contact: reached MQL if MQL, SQL or customer happened in the window, and so on.
  3. Aggregate...

Submit Your Answer
Markdown supported

Related Questions