Nonprofit Donor Retention and Cohort LTV SQL Brief
Develop analytical SQL pipelines to calculate donor cohort retention, giving velocity, and lapse patterns across fundraising campaigns.
Use this template when analyzing donor lifecycle behaviors across philanthropic campaigns in a nonprofit data warehouse. It yields an analytical SQL strategy and code structure for cohort-based lifetime value calculations.
Role: Lead Nonprofit Analytics Engineer specializing in donor lifecycle modeling and fundraising data warehouse architecture.
Context
- Source CRM Data Schema: {{crm_source_schema}}
- Analytical Database Engine: {{reporting_database_engine}}
- Cohort Evaluation Window: {{retention_window_months}}
- Donor Giving Tier Boundaries: {{giving_tier_thresholds}}
- Lapse Threshold Definition: {{lapse_definition_days}}
- Evaluated Campaign Types: {{target_campaign_types}}
Task
Author a donor retention SQL architecture brief that creates scalable cohort models, evaluates giving trajectory over time, and isolates donor lapse indicators across {{target_campaign_types}} to guide nonprofit stewardship strategies.
Method
- Inspect entity relationships within {{crm_source_schema}} to isolate first-gift acquisition dates per donor entity.
- Construct acquisition cohort groups partitioned by calendar quarter and initial gift amount using {{giving_tier_thresholds}}.
- Compute rolling retention intervals using date-difference expressions aligned with {{retention_window_months}}.
- Apply advanced analytic window functions (
DENSE_RANK(),LEAD(),LAG()) to calculate days elapsed between consecutive contributions. - Categorize donors as active, renewed, upgraded, or lapsed based on the parameter {{lapse_definition_days}}.
- Aggregate cumulative lifetime value (LTV) across distinct cohorts to track revenue yield curves.
- Isolate multi-year giving trends across distinct categories in {{target_campaign_types}} to identify channel decay.
Constraints
- MUST optimize queries to prevent Cartesian products when joining high-volume transactional tables.
- MUST NOT drop zero-dollar pledge records without explicit defensive filtering in CTE comments.
- All cohort definitions MUST rely on deterministic date math native to {{reporting_database_engine}}.
- Code must exclude recurring automated test records and internal staff donor accounts.
- Query performance must support partitioning by donor state or region without full table scans.
Output format
Structure the deliverable into four sequential sections:
- Metric Definitions & Transformation Logic (max 200 words)
- Staged Data Pipeline Blueprint (numbered sequence)
- Production SQL Cohort Analysis Script (complete, commented code block)
- Performance Optimization & Materialization Plan (max 250 words)
Self-review
- Confirm cohort window arithmetic aligns with {{retention_window_months}} boundaries.
- Verify that tier categorization correctly handles edge values defined in {{giving_tier_thresholds}}.
- Check that donor churn classification honors the {{lapse_definition_days}} parameter.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.