Learning PathLesson 3 of 7 · Advanced Analytics
Advanced Analytics · Lesson 3 of 7advanced12 min read

Customer Segmentation & Cohort Analysis

Use AI to build RFM analyses, behavioral segments, and cohort retention curves. Practical SQL queries and prompts for smarter customer segmentation.

Why Most Segmentation Is Too Simple

Most marketing teams segment by plan tier and maybe company size. That's table stakes. The analysts who drive real business impact segment by behavior — who's actually using the product, who's at risk, who looks like your best customers but hasn't upgraded yet. AI makes this level of segmentation accessible without a data science degree.

RFM Analysis: The Foundation

RFM (Recency, Frequency, Monetary) is the classic segmentation framework, and it's still incredibly useful. Recency = how recently they purchased or engaged. Frequency = how often they engage. Monetary = how much they spend. Score each dimension 1-5 and you get instant customer tiers.

rfm_segmentation.sqlsql
WITH rfm_raw AS (
  SELECT
    customer_id,
    DATEDIFF(day, MAX(order_date), CURRENT_DATE) AS recency_days,
    COUNT(DISTINCT order_id) AS frequency,
    SUM(order_value) AS monetary
  FROM orders
  WHERE order_date >= DATEADD(year, -1, CURRENT_DATE)
  GROUP BY customer_id
),
rfm_scored AS (
  SELECT
    customer_id,
    recency_days,
    frequency,
    monetary,
    NTILE(5) OVER (ORDER BY recency_days ASC) AS r_score,
    NTILE(5) OVER (ORDER BY frequency ASC) AS f_score,
    NTILE(5) OVER (ORDER BY monetary ASC) AS m_score
  FROM rfm_raw
)
SELECT
  customer_id,
  r_score,
  f_score,
  m_score,
  CONCAT(r_score, f_score, m_score) AS rfm_segment,
  CASE
    WHEN r_score >= 4 AND f_score >= 4 AND m_score >= 4 THEN 'Champions'
    WHEN r_score >= 4 AND f_score >= 3 THEN 'Loyal Customers'
    WHEN r_score >= 4 AND f_score <= 2 THEN 'New Customers'
    WHEN r_score <= 2 AND f_score >= 3 THEN 'At Risk'
    WHEN r_score <= 2 AND f_score <= 2 AND m_score >= 3 THEN 'Can''t Lose Them'
    WHEN r_score <= 2 AND f_score <= 2 AND m_score <= 2 THEN 'Hibernating'
    ELSE 'Needs Attention'
  END AS segment_label
FROM rfm_scored
ORDER BY monetary DESC;
Prompt Example
any

Turn RFM segments into a concrete marketing action plan

I have an RFM analysis with these segments and customer counts: Champions (450), Loyal (1,200), New Customers (800), At Risk (650), Can't Lose Them (180), Hibernating (2,100). Our average order value is $85 and customer acquisition cost is $45. For each segment, give me: (1) a specific marketing action to take this month, (2) the expected ROI of that action, (3) which channels to use, and (4) how to measure success. Prioritize the segments by potential revenue impact.

Behavioral Segmentation with AI

RFM is based on transaction data. Behavioral segmentation goes deeper — it looks at how people actually use your product or interact with your marketing. Which features do they use? What content do they consume? How do they navigate your site? AI is particularly good at finding behavioral patterns humans would miss.

Prompt Example
claude

Discover natural behavioral segments in your product usage data

I have product usage data for a SaaS platform with these event types: login, feature_A_used, feature_B_used, report_generated, invite_sent, settings_changed, support_ticket_opened, export_data. I want to identify natural behavioral segments. Help me: (1) Write SQL to create a user-level behavioral feature table, (2) Identify 4-6 meaningful behavioral segments, (3) Name each segment with a descriptive label, (4) Suggest marketing actions for each segment. Focus on segments that predict retention and expansion revenue.

Cohort Retention Curves

Cohort analysis tells you something no other analysis can: are things getting better or worse over time? By grouping customers by signup month and tracking their retention, you see whether product improvements and marketing changes are actually working.

cohort_retention.sqlsql
WITH cohorts AS (
  SELECT
    customer_id,
    DATE_TRUNC('month', first_order_date) AS cohort_month
  FROM customers
),
activity AS (
  SELECT
    c.customer_id,
    c.cohort_month,
    DATE_TRUNC('month', o.order_date) AS activity_month,
    DATEDIFF('month', c.cohort_month, DATE_TRUNC('month', o.order_date)) AS months_since_first
  FROM cohorts c
  JOIN orders o ON c.customer_id = o.customer_id
)
SELECT
  cohort_month,
  months_since_first,
  COUNT(DISTINCT customer_id) AS active_customers,
  ROUND(
    COUNT(DISTINCT customer_id) * 100.0 /
    FIRST_VALUE(COUNT(DISTINCT customer_id)) OVER (
      PARTITION BY cohort_month ORDER BY months_since_first
    ), 1
  ) AS retention_pct
FROM activity
GROUP BY cohort_month, months_since_first
ORDER BY cohort_month, months_since_first;

Manual Workflow

Building cohort tables manually in Excel, taking an entire day to create one retention curve, unable to quickly compare segments.

With AI

AI generates cohort SQL, interprets the retention curves, flags concerning trends, and suggests which cohorts to investigate further — all in under 30 minutes.
Time saved: 6+ hours per cohort analysis
AI Generatedclaude
Looking at your cohort data, I see three key patterns: 1. **Month-3 cliff**: Across all cohorts, you lose ~40% of customers between months 2-3. This suggests an onboarding or activation problem — customers try the product but don't build it into their workflow. 2. **Recent cohorts are improving**: Your Jan 2026 cohort has 68% month-1 retention vs. 52% for Oct 2025. Whatever changes you made in Q4 are working. 3. **Segment divergence**: Enterprise cohorts flatten at ~75% retention after month ...
Pro Tip
Always compare cohort curves across segments, not just across time periods. A cohort that looks healthy in aggregate might be hiding a terrible retention problem in one segment and an amazing one in another.

Combining Segmentation Approaches

The real power comes from combining RFM, behavioral, and cohort analyses. Your Champions segment from RFM should map to your Power Users in behavioral segmentation. If they don't, you've found a disconnect worth investigating. AI can help you cross-reference these models and find the overlaps and gaps.

Try It Yourself

Build an RFM analysis on your own customer data and ask AI to create an action plan

Here is my RFM segmentation data: [paste segment names, counts, and average revenue per segment]. Also, here are my cohort retention rates for the last 6 months: [paste retention data]. Help me: (1) Identify which RFM segments are growing vs. shrinking over time, (2) Find the highest-ROI segment to focus on this quarter, (3) Create a one-page executive summary I can present to leadership with specific recommendations and expected revenue impact.
Watch Out
Segmentation is only useful if your team can act on it. Five clear segments with specific actions beat twenty granular segments that nobody can operationalize. Start simple and add complexity only when you've proven the basic segments drive results.

Get weekly job alerts

Curated marketing analytics roles — delivered every Monday.