SQL
AuraScore 81/100

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.

Template

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

  1. Inspect entity relationships within {{crm_source_schema}} to isolate first-gift acquisition dates per donor entity.
  2. Construct acquisition cohort groups partitioned by calendar quarter and initial gift amount using {{giving_tier_thresholds}}.
  3. Compute rolling retention intervals using date-difference expressions aligned with {{retention_window_months}}.
  4. Apply advanced analytic window functions (DENSE_RANK(), LEAD(), LAG()) to calculate days elapsed between consecutive contributions.
  5. Categorize donors as active, renewed, upgraded, or lapsed based on the parameter {{lapse_definition_days}}.
  6. Aggregate cumulative lifetime value (LTV) across distinct cohorts to track revenue yield curves.
  7. 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:

  1. Metric Definitions & Transformation Logic (max 200 words)
  2. Staged Data Pipeline Blueprint (numbered sequence)
  3. Production SQL Cohort Analysis Script (complete, commented code block)
  4. 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.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-sql
public-sector-nonprofit
sql
nonprofit
cohort-analysis