This was a lot to hold in your head at once.
Start by defining the base subscriber cohort using a subquery that finds each company's earliest non-null subscription date, then aggregate to monthly counts. Build a dynamic month spine from the minimum date to the data watermark using a recursive CTE or date functions, left join the counts, and use a self-join with a 12-month lag to compute YoY deltas with safe division. Finally, flag partial months by comparing each month to the watermark.
Pro tip: Always anchor the month spine to the data watermark (e.g., MAX(subscription_date)) rather than CURRENT_DATE to avoid misaligned partial months in historical snapshots, and explicitly state that the partial month flag should be used to filter out incomplete months in downstream reporting.
Use a subquery to find each company's earliest non-null subscription date, then filter to those with a date on or after June 2019. This defines the cohort of new subscribers.
Group the cohort by the month of their earliest subscription date and count distinct companies to get the number of new subscribers per month.
Create a series of months from June 2019 up to the data watermark (e.g., using a recursive CTE or GENERATE_DATE_ARRAY) without hardcoding the end date, then left join the monthly counts and zero-fill missing months.
Self-join the monthly counts to the same table shifted by 12 months (using a lag window function or a date offset) to get the prior-year count for each month.
Use safe division (e.g., NULLIF or CASE) to compute the YoY percentage change, and flag months as partial if the month equals the month of the data watermark (or if the watermark is not the last day of the month).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.