Skip to content
AGAhmed Gomaa.
Customer analytics

RFM Analysis: Segment Your Customers by Behavior, Not Guesswork

Most businesses know their total sales but not who is actually driving them. RFM analysis answers that with three numbers per customer, taken straight from your order history, and turns a long customer list into a few groups you can act on.

Ahmed GomaaOct 17, 20266 min read

What RFM measures

RFM stands for Recency, Frequency and Monetary value. Each one describes a different side of customer behavior:

  • Recency: how many days have passed since the customer's last purchase. Recent buyers are more likely to buy again.
  • Frequency: how many orders the customer placed in the period you analyze. Repeat buyers are more loyal than one-time buyers.
  • Monetary: how much the customer spent in total. This separates high-value customers from low-value ones.

All you need is a transactions table with a customer ID, an order date and an order value.

Step 1: Prepare the order data

Keep one row per order. Remove cancelled, test and duplicate orders, and decide how returns are handled: either deduct them from the order value or exclude fully returned orders. Then fix a snapshot date, usually the day after your latest order, so that recency is measured the same way for every customer.

Step 2: Calculate the three metrics and score them

For each customer, recency is the snapshot date minus the last order date, frequency is the number of distinct orders, and monetary is the sum of net order value. Then rank customers on each metric and give a score from 1 to 5, where 5 is best. In PostgreSQL this takes one query:

WITH rfm AS (
  SELECT customer_id,
         CURRENT_DATE - MAX(order_date)::date AS recency_days,
         COUNT(DISTINCT order_id)            AS frequency,
         SUM(order_value)                    AS monetary
  FROM orders
  WHERE status = 'completed'
  GROUP BY customer_id
)
SELECT *,
  NTILE(5) OVER (ORDER BY recency_days DESC) AS r_score,
  NTILE(5) OVER (ORDER BY frequency)         AS f_score,
  NTILE(5) OVER (ORDER BY monetary)          AS m_score
FROM rfm;

Note that recency is sorted in descending order so that the most recent customers receive the highest score. The same idea works in Excel with PERCENTRANK or in Python with pandas qcut.

Step 3: Turn scores into segments you can act on

Raw scores are not a strategy. Combine them into a handful of named groups, each with a clear action:

  • Champions (high R, F and M): reward them, ask for reviews and offer early access.
  • Loyal customers (high F, good R): keep them engaged with a loyalty benefit and relevant cross-sell offers.
  • New customers (high R, low F): a good first-purchase experience and a simple second-purchase offer matter most.
  • At risk (low R, high F or M): these were valuable and are slipping away. A personal win-back message is worth more here than a mass discount.
  • Hibernating (low R, F and M): use low-cost reactivation, and stop spending heavily on them if they do not respond.

Common mistakes to avoid

  • Using too many segments. Five to eight groups that each have a different action are enough.
  • Ignoring returns and cancellations, which inflates both frequency and monetary value.
  • Treating segments as permanent. Re-run the analysis every month or quarter and track how customers move between groups.
  • Stopping at the analysis. A segment without a decision attached to it is just a label.

Frequently asked questions

How much data do I need for RFM analysis?

A table of orders with customer ID, date and value is enough. Results become more reliable with at least several hundred customers and 6 to 12 months of history.

Is RFM only for online stores?

No. It works for any business that records repeat purchases per customer, such as retail, restaurants, clinics, subscriptions and B2B accounts.

Can I do RFM in Excel?

Yes. Summarize orders per customer with a PivotTable or Power Query, then score each metric with PERCENTRANK or quartiles. SQL or Python is easier once the data grows.

Want this done on your own data?

Tell me what you are trying to understand and what data you have. I will reply with a clear next step.