Members Who Switched From Brand to Generic Within Ninety Days

Last updated: November 29, 2026

Quick Overview

Using claims (member_id, fill_date, gpi, is_brand) where gpi identifies the clinical drug, find members who filled a brand version of a drug and then filled the generic version of the same gpi within 90 days, and report the switch rate per gpi.

CVS Health
Data Manipulation (SQL/Python)
Data Scientist
CVS Health
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Using claims (member_id, fill_date, gpi, is_brand) where gpi identifies the clinical drug, find members who filled a brand version of a drug and then filled the generic version of the same gpi within 90 days, and report the switch rate per gpi.

CVS Caremark, the pharmacy benefit manager, tracks generic dispensing and brand to generic conversion because it drives plan cost. The interviewer checks self-join logic with time bounds and a sound denominator.

What the Interviewer Expects
  • Self-joins on member and drug identifier with a time window
  • Requires the generic fill to come after the brand fill
  • Counts distinct members to avoid double counting multiple fills
  • Defines the switch rate denominator clearly
  • Considers members whose 90 day window is not complete
Key Topics to Cover
self join
time window join
EXISTS
PBM analytics
denominators
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
  • How would you find members who switched back to brand afterward?
  • How would you write this with window functions instead of a self-join?
  • How would you adjust for generics that launched mid-year?
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

claims(member_id, fill_date, gpi, is_brand). GPI groups the same molecule, strength and form across manufacturers. A switcher has a brand fill on date d and a generic fill on the same gpi in (d, d +...

Approach

Take each member's first brand fill per gpi. Use EXISTS to check for a generic fill in the window, which avoids duplicate rows from multiple generic fills. Restrict to members with a complete window, ...


Submit Your Answer
Markdown supported