Part IV — Business workflows · Chapter 11

Cohort retention for an online shop, from one Excel workbook

A UK online gift wholesaler's two years of invoices, read straight from Excel: about one new customer in five orders again the next month, returning customers bring in 80% to 91% of revenue, and in 2011 the shop held revenue flat on half as many new customers.

On this page
  1. What the workbook holds
  2. From workbook to cohort table
  3. How fast customers come back
  4. Revenue rests on customers who came back
  5. Who to call: recent, frequent and lapsing customers
  6. Explore the shop's books yourself
  7. Reusing the workflow

About one new customer in five orders again the month after the first order: 21% on average across 22 monthly cohorts. Most come back eventually, though. Of the customers who had a full year to come back, 71% did, and returning customers brought in 80% of revenue in 2010 and 91% in 2011. Those are the cohort numbers a retailer's growth team watches, here computed from the invoices of a UK online shop that sells gifts and homewares, mostly to other businesses.

The data comes as a two-sheet Excel workbook, which is how a lot of business data arrives. This chapter reads it in place with DuckDB's excel extension. It then fixes the three things that would skew a cohort table: the sheets overlap, a fifth of the lines have no customer, and the first month mixes new customers with everyone who was already buying.

On average 21% of a cohort orders again the next month and 14% in month 11, then more return near Christmas

Months since first order14710131619222009-12 (and earlier)Cohort (month of first order) 2009-12 (and earlier), months since first order 1: 35.0%Cohort (month of first order) 2009-12 (and earlier), months since first order 2: 33.3%Cohort (month of first order) 2009-12 (and earlier), months since first order 3: 42.5%Cohort (month of first order) 2009-12 (and earlier), months since first order 4: 37.9%Cohort (month of first order) 2009-12 (and earlier), months since first order 5: 36.0%Cohort (month of first order) 2009-12 (and earlier), months since first order 6: 37.6%Cohort (month of first order) 2009-12 (and earlier), months since first order 7: 34.4%Cohort (month of first order) 2009-12 (and earlier), months since first order 8: 33.8%Cohort (month of first order) 2009-12 (and earlier), months since first order 9: 36.2%Cohort (month of first order) 2009-12 (and earlier), months since first order 10: 42.2%Cohort (month of first order) 2009-12 (and earlier), months since first order 11: 49.6%Cohort (month of first order) 2009-12 (and earlier), months since first order 12: 37.6%Cohort (month of first order) 2009-12 (and earlier), months since first order 13: 28.2%Cohort (month of first order) 2009-12 (and earlier), months since first order 14: 24.4%Cohort (month of first order) 2009-12 (and earlier), months since first order 15: 30.3%Cohort (month of first order) 2009-12 (and earlier), months since first order 16: 26.3%Cohort (month of first order) 2009-12 (and earlier), months since first order 17: 30.3%Cohort (month of first order) 2009-12 (and earlier), months since first order 18: 28.4%Cohort (month of first order) 2009-12 (and earlier), months since first order 19: 25.9%Cohort (month of first order) 2009-12 (and earlier), months since first order 20: 25.4%Cohort (month of first order) 2009-12 (and earlier), months since first order 21: 31.3%Cohort (month of first order) 2009-12 (and earlier), months since first order 22: 30.4%Cohort (month of first order) 2009-12 (and earlier), months since first order 23: 40.6%Cohort (month of first order) 2009-12 (and earlier), months since first order 24: no data2010-01Cohort (month of first order) 2010-01, months since first order 1: 21.5%Cohort (month of first order) 2010-01, months since first order 2: 32.1%Cohort (month of first order) 2010-01, months since first order 3: 31.5%Cohort (month of first order) 2010-01, months since first order 4: 27.2%Cohort (month of first order) 2010-01, months since first order 5: 31.0%Cohort (month of first order) 2010-01, months since first order 6: 26.9%Cohort (month of first order) 2010-01, months since first order 7: 23.4%Cohort (month of first order) 2010-01, months since first order 8: 28.5%Cohort (month of first order) 2010-01, months since first order 9: 32.6%Cohort (month of first order) 2010-01, months since first order 10: 31.0%Cohort (month of first order) 2010-01, months since first order 11: 17.9%Cohort (month of first order) 2010-01, months since first order 12: 22.8%Cohort (month of first order) 2010-01, months since first order 13: 17.9%Cohort (month of first order) 2010-01, months since first order 14: 19.6%Cohort (month of first order) 2010-01, months since first order 15: 15.2%Cohort (month of first order) 2010-01, months since first order 16: 24.5%Cohort (month of first order) 2010-01, months since first order 17: 20.4%Cohort (month of first order) 2010-01, months since first order 18: 19.3%Cohort (month of first order) 2010-01, months since first order 19: 20.1%Cohort (month of first order) 2010-01, months since first order 20: 25.3%Cohort (month of first order) 2010-01, months since first order 21: 19.8%Cohort (month of first order) 2010-01, months since first order 22: 25.3%Cohort (month of first order) 2010-01, months since first order 23: no dataCohort (month of first order) 2010-01, months since first order 24: no data2010-02Cohort (month of first order) 2010-02, months since first order 1: 23.5%Cohort (month of first order) 2010-02, months since first order 2: 22.7%Cohort (month of first order) 2010-02, months since first order 3: 29.3%Cohort (month of first order) 2010-02, months since first order 4: 24.5%Cohort (month of first order) 2010-02, months since first order 5: 19.7%Cohort (month of first order) 2010-02, months since first order 6: 19.2%Cohort (month of first order) 2010-02, months since first order 7: 28.8%Cohort (month of first order) 2010-02, months since first order 8: 25.6%Cohort (month of first order) 2010-02, months since first order 9: 27.7%Cohort (month of first order) 2010-02, months since first order 10: 11.5%Cohort (month of first order) 2010-02, months since first order 11: 12.5%Cohort (month of first order) 2010-02, months since first order 12: 15.2%Cohort (month of first order) 2010-02, months since first order 13: 17.6%Cohort (month of first order) 2010-02, months since first order 14: 12.3%Cohort (month of first order) 2010-02, months since first order 15: 20.0%Cohort (month of first order) 2010-02, months since first order 16: 16.0%Cohort (month of first order) 2010-02, months since first order 17: 16.3%Cohort (month of first order) 2010-02, months since first order 18: 14.4%Cohort (month of first order) 2010-02, months since first order 19: 22.9%Cohort (month of first order) 2010-02, months since first order 20: 22.9%Cohort (month of first order) 2010-02, months since first order 21: 16.5%Cohort (month of first order) 2010-02, months since first order 22: no dataCohort (month of first order) 2010-02, months since first order 23: no dataCohort (month of first order) 2010-02, months since first order 24: no data2010-03Cohort (month of first order) 2010-03, months since first order 1: 19.0%Cohort (month of first order) 2010-03, months since first order 2: 23.1%Cohort (month of first order) 2010-03, months since first order 3: 24.3%Cohort (month of first order) 2010-03, months since first order 4: 23.1%Cohort (month of first order) 2010-03, months since first order 5: 20.4%Cohort (month of first order) 2010-03, months since first order 6: 24.7%Cohort (month of first order) 2010-03, months since first order 7: 30.6%Cohort (month of first order) 2010-03, months since first order 8: 27.7%Cohort (month of first order) 2010-03, months since first order 9: 10.9%Cohort (month of first order) 2010-03, months since first order 10: 11.6%Cohort (month of first order) 2010-03, months since first order 11: 14.5%Cohort (month of first order) 2010-03, months since first order 12: 20.0%Cohort (month of first order) 2010-03, months since first order 13: 16.3%Cohort (month of first order) 2010-03, months since first order 14: 20.0%Cohort (month of first order) 2010-03, months since first order 15: 17.0%Cohort (month of first order) 2010-03, months since first order 16: 17.5%Cohort (month of first order) 2010-03, months since first order 17: 15.6%Cohort (month of first order) 2010-03, months since first order 18: 17.7%Cohort (month of first order) 2010-03, months since first order 19: 20.4%Cohort (month of first order) 2010-03, months since first order 20: 21.3%Cohort (month of first order) 2010-03, months since first order 21: no dataCohort (month of first order) 2010-03, months since first order 22: no dataCohort (month of first order) 2010-03, months since first order 23: no dataCohort (month of first order) 2010-03, months since first order 24: no data2010-04Cohort (month of first order) 2010-04, months since first order 1: 19.0%Cohort (month of first order) 2010-04, months since first order 2: 19.0%Cohort (month of first order) 2010-04, months since first order 3: 16.0%Cohort (month of first order) 2010-04, months since first order 4: 18.4%Cohort (month of first order) 2010-04, months since first order 5: 22.1%Cohort (month of first order) 2010-04, months since first order 6: 27.6%Cohort (month of first order) 2010-04, months since first order 7: 26.5%Cohort (month of first order) 2010-04, months since first order 8: 10.5%Cohort (month of first order) 2010-04, months since first order 9: 10.9%Cohort (month of first order) 2010-04, months since first order 10: 7.5%Cohort (month of first order) 2010-04, months since first order 11: 13.9%Cohort (month of first order) 2010-04, months since first order 12: 14.3%Cohort (month of first order) 2010-04, months since first order 13: 15.6%Cohort (month of first order) 2010-04, months since first order 14: 15.6%Cohort (month of first order) 2010-04, months since first order 15: 15.6%Cohort (month of first order) 2010-04, months since first order 16: 13.9%Cohort (month of first order) 2010-04, months since first order 17: 15.0%Cohort (month of first order) 2010-04, months since first order 18: 18.0%Cohort (month of first order) 2010-04, months since first order 19: 22.8%Cohort (month of first order) 2010-04, months since first order 20: no dataCohort (month of first order) 2010-04, months since first order 21: no dataCohort (month of first order) 2010-04, months since first order 22: no dataCohort (month of first order) 2010-04, months since first order 23: no dataCohort (month of first order) 2010-04, months since first order 24: no data2010-05Cohort (month of first order) 2010-05, months since first order 1: 15.7%Cohort (month of first order) 2010-05, months since first order 2: 16.9%Cohort (month of first order) 2010-05, months since first order 3: 17.6%Cohort (month of first order) 2010-05, months since first order 4: 17.6%Cohort (month of first order) 2010-05, months since first order 5: 25.5%Cohort (month of first order) 2010-05, months since first order 6: 21.2%Cohort (month of first order) 2010-05, months since first order 7: 12.5%Cohort (month of first order) 2010-05, months since first order 8: 5.9%Cohort (month of first order) 2010-05, months since first order 9: 8.2%Cohort (month of first order) 2010-05, months since first order 10: 11.4%Cohort (month of first order) 2010-05, months since first order 11: 13.3%Cohort (month of first order) 2010-05, months since first order 12: 15.3%Cohort (month of first order) 2010-05, months since first order 13: 15.3%Cohort (month of first order) 2010-05, months since first order 14: 9.8%Cohort (month of first order) 2010-05, months since first order 15: 12.5%Cohort (month of first order) 2010-05, months since first order 16: 13.7%Cohort (month of first order) 2010-05, months since first order 17: 16.5%Cohort (month of first order) 2010-05, months since first order 18: 15.3%Cohort (month of first order) 2010-05, months since first order 19: no dataCohort (month of first order) 2010-05, months since first order 20: no dataCohort (month of first order) 2010-05, months since first order 21: no dataCohort (month of first order) 2010-05, months since first order 22: no dataCohort (month of first order) 2010-05, months since first order 23: no dataCohort (month of first order) 2010-05, months since first order 24: no data2010-06Cohort (month of first order) 2010-06, months since first order 1: 17.6%Cohort (month of first order) 2010-06, months since first order 2: 18.7%Cohort (month of first order) 2010-06, months since first order 3: 20.6%Cohort (month of first order) 2010-06, months since first order 4: 23.2%Cohort (month of first order) 2010-06, months since first order 5: 28.5%Cohort (month of first order) 2010-06, months since first order 6: 12.7%Cohort (month of first order) 2010-06, months since first order 7: 9.0%Cohort (month of first order) 2010-06, months since first order 8: 8.2%Cohort (month of first order) 2010-06, months since first order 9: 11.2%Cohort (month of first order) 2010-06, months since first order 10: 10.5%Cohort (month of first order) 2010-06, months since first order 11: 13.9%Cohort (month of first order) 2010-06, months since first order 12: 15.0%Cohort (month of first order) 2010-06, months since first order 13: 12.4%Cohort (month of first order) 2010-06, months since first order 14: 11.2%Cohort (month of first order) 2010-06, months since first order 15: 12.4%Cohort (month of first order) 2010-06, months since first order 16: 13.1%Cohort (month of first order) 2010-06, months since first order 17: 20.2%Cohort (month of first order) 2010-06, months since first order 18: no dataCohort (month of first order) 2010-06, months since first order 19: no dataCohort (month of first order) 2010-06, months since first order 20: no dataCohort (month of first order) 2010-06, months since first order 21: no dataCohort (month of first order) 2010-06, months since first order 22: no dataCohort (month of first order) 2010-06, months since first order 23: no dataCohort (month of first order) 2010-06, months since first order 24: no data2010-07Cohort (month of first order) 2010-07, months since first order 1: 15.7%Cohort (month of first order) 2010-07, months since first order 2: 18.4%Cohort (month of first order) 2010-07, months since first order 3: 29.7%Cohort (month of first order) 2010-07, months since first order 4: 29.2%Cohort (month of first order) 2010-07, months since first order 5: 14.1%Cohort (month of first order) 2010-07, months since first order 6: 11.4%Cohort (month of first order) 2010-07, months since first order 7: 14.6%Cohort (month of first order) 2010-07, months since first order 8: 14.6%Cohort (month of first order) 2010-07, months since first order 9: 11.4%Cohort (month of first order) 2010-07, months since first order 10: 13.5%Cohort (month of first order) 2010-07, months since first order 11: 14.6%Cohort (month of first order) 2010-07, months since first order 12: 13.0%Cohort (month of first order) 2010-07, months since first order 13: 13.5%Cohort (month of first order) 2010-07, months since first order 14: 19.5%Cohort (month of first order) 2010-07, months since first order 15: 17.3%Cohort (month of first order) 2010-07, months since first order 16: 23.8%Cohort (month of first order) 2010-07, months since first order 17: no dataCohort (month of first order) 2010-07, months since first order 18: no dataCohort (month of first order) 2010-07, months since first order 19: no dataCohort (month of first order) 2010-07, months since first order 20: no dataCohort (month of first order) 2010-07, months since first order 21: no dataCohort (month of first order) 2010-07, months since first order 22: no dataCohort (month of first order) 2010-07, months since first order 23: no dataCohort (month of first order) 2010-07, months since first order 24: no data2010-08Cohort (month of first order) 2010-08, months since first order 1: 19.6%Cohort (month of first order) 2010-08, months since first order 2: 28.8%Cohort (month of first order) 2010-08, months since first order 3: 32.5%Cohort (month of first order) 2010-08, months since first order 4: 16.6%Cohort (month of first order) 2010-08, months since first order 5: 11.7%Cohort (month of first order) 2010-08, months since first order 6: 9.8%Cohort (month of first order) 2010-08, months since first order 7: 12.9%Cohort (month of first order) 2010-08, months since first order 8: 13.5%Cohort (month of first order) 2010-08, months since first order 9: 12.9%Cohort (month of first order) 2010-08, months since first order 10: 12.9%Cohort (month of first order) 2010-08, months since first order 11: 11.7%Cohort (month of first order) 2010-08, months since first order 12: 14.7%Cohort (month of first order) 2010-08, months since first order 13: 17.2%Cohort (month of first order) 2010-08, months since first order 14: 17.2%Cohort (month of first order) 2010-08, months since first order 15: 19.6%Cohort (month of first order) 2010-08, months since first order 16: no dataCohort (month of first order) 2010-08, months since first order 17: no dataCohort (month of first order) 2010-08, months since first order 18: no dataCohort (month of first order) 2010-08, months since first order 19: no dataCohort (month of first order) 2010-08, months since first order 20: no dataCohort (month of first order) 2010-08, months since first order 21: no dataCohort (month of first order) 2010-08, months since first order 22: no dataCohort (month of first order) 2010-08, months since first order 23: no dataCohort (month of first order) 2010-08, months since first order 24: no data2010-09Cohort (month of first order) 2010-09, months since first order 1: 23.0%Cohort (month of first order) 2010-09, months since first order 2: 23.4%Cohort (month of first order) 2010-09, months since first order 3: 13.0%Cohort (month of first order) 2010-09, months since first order 4: 8.8%Cohort (month of first order) 2010-09, months since first order 5: 10.5%Cohort (month of first order) 2010-09, months since first order 6: 13.8%Cohort (month of first order) 2010-09, months since first order 7: 9.6%Cohort (month of first order) 2010-09, months since first order 8: 13.0%Cohort (month of first order) 2010-09, months since first order 9: 13.0%Cohort (month of first order) 2010-09, months since first order 10: 12.1%Cohort (month of first order) 2010-09, months since first order 11: 10.0%Cohort (month of first order) 2010-09, months since first order 12: 22.6%Cohort (month of first order) 2010-09, months since first order 13: 16.7%Cohort (month of first order) 2010-09, months since first order 14: 16.7%Cohort (month of first order) 2010-09, months since first order 15: no dataCohort (month of first order) 2010-09, months since first order 16: no dataCohort (month of first order) 2010-09, months since first order 17: no dataCohort (month of first order) 2010-09, months since first order 18: no dataCohort (month of first order) 2010-09, months since first order 19: no dataCohort (month of first order) 2010-09, months since first order 20: no dataCohort (month of first order) 2010-09, months since first order 21: no dataCohort (month of first order) 2010-09, months since first order 22: no dataCohort (month of first order) 2010-09, months since first order 23: no dataCohort (month of first order) 2010-09, months since first order 24: no data2010-10Cohort (month of first order) 2010-10, months since first order 1: 25.9%Cohort (month of first order) 2010-10, months since first order 2: 14.7%Cohort (month of first order) 2010-10, months since first order 3: 12.5%Cohort (month of first order) 2010-10, months since first order 4: 8.8%Cohort (month of first order) 2010-10, months since first order 5: 8.3%Cohort (month of first order) 2010-10, months since first order 6: 13.1%Cohort (month of first order) 2010-10, months since first order 7: 13.9%Cohort (month of first order) 2010-10, months since first order 8: 10.7%Cohort (month of first order) 2010-10, months since first order 9: 9.3%Cohort (month of first order) 2010-10, months since first order 10: 10.7%Cohort (month of first order) 2010-10, months since first order 11: 12.8%Cohort (month of first order) 2010-10, months since first order 12: 19.2%Cohort (month of first order) 2010-10, months since first order 13: 23.2%Cohort (month of first order) 2010-10, months since first order 14: no dataCohort (month of first order) 2010-10, months since first order 15: no dataCohort (month of first order) 2010-10, months since first order 16: no dataCohort (month of first order) 2010-10, months since first order 17: no dataCohort (month of first order) 2010-10, months since first order 18: no dataCohort (month of first order) 2010-10, months since first order 19: no dataCohort (month of first order) 2010-10, months since first order 20: no dataCohort (month of first order) 2010-10, months since first order 21: no dataCohort (month of first order) 2010-10, months since first order 22: no dataCohort (month of first order) 2010-10, months since first order 23: no dataCohort (month of first order) 2010-10, months since first order 24: no data2010-11Cohort (month of first order) 2010-11, months since first order 1: 17.5%Cohort (month of first order) 2010-11, months since first order 2: 9.5%Cohort (month of first order) 2010-11, months since first order 3: 9.5%Cohort (month of first order) 2010-11, months since first order 4: 7.7%Cohort (month of first order) 2010-11, months since first order 5: 8.9%Cohort (month of first order) 2010-11, months since first order 6: 12.9%Cohort (month of first order) 2010-11, months since first order 7: 10.1%Cohort (month of first order) 2010-11, months since first order 8: 8.6%Cohort (month of first order) 2010-11, months since first order 9: 9.2%Cohort (month of first order) 2010-11, months since first order 10: 11.0%Cohort (month of first order) 2010-11, months since first order 11: 14.7%Cohort (month of first order) 2010-11, months since first order 12: 25.2%Cohort (month of first order) 2010-11, months since first order 13: no dataCohort (month of first order) 2010-11, months since first order 14: no dataCohort (month of first order) 2010-11, months since first order 15: no dataCohort (month of first order) 2010-11, months since first order 16: no dataCohort (month of first order) 2010-11, months since first order 17: no dataCohort (month of first order) 2010-11, months since first order 18: no dataCohort (month of first order) 2010-11, months since first order 19: no dataCohort (month of first order) 2010-11, months since first order 20: no dataCohort (month of first order) 2010-11, months since first order 21: no dataCohort (month of first order) 2010-11, months since first order 22: no dataCohort (month of first order) 2010-11, months since first order 23: no dataCohort (month of first order) 2010-11, months since first order 24: no data2010-12Cohort (month of first order) 2010-12, months since first order 1: 9.2%Cohort (month of first order) 2010-12, months since first order 2: 5.3%Cohort (month of first order) 2010-12, months since first order 3: 9.2%Cohort (month of first order) 2010-12, months since first order 4: 11.8%Cohort (month of first order) 2010-12, months since first order 5: 6.6%Cohort (month of first order) 2010-12, months since first order 6: 5.3%Cohort (month of first order) 2010-12, months since first order 7: 9.2%Cohort (month of first order) 2010-12, months since first order 8: 5.3%Cohort (month of first order) 2010-12, months since first order 9: 2.6%Cohort (month of first order) 2010-12, months since first order 10: 9.2%Cohort (month of first order) 2010-12, months since first order 11: 19.7%Cohort (month of first order) 2010-12, months since first order 12: no dataCohort (month of first order) 2010-12, months since first order 13: no dataCohort (month of first order) 2010-12, months since first order 14: no dataCohort (month of first order) 2010-12, months since first order 15: no dataCohort (month of first order) 2010-12, months since first order 16: no dataCohort (month of first order) 2010-12, months since first order 17: no dataCohort (month of first order) 2010-12, months since first order 18: no dataCohort (month of first order) 2010-12, months since first order 19: no dataCohort (month of first order) 2010-12, months since first order 20: no dataCohort (month of first order) 2010-12, months since first order 21: no dataCohort (month of first order) 2010-12, months since first order 22: no dataCohort (month of first order) 2010-12, months since first order 23: no dataCohort (month of first order) 2010-12, months since first order 24: no data2011-01Cohort (month of first order) 2011-01, months since first order 1: 16.7%Cohort (month of first order) 2011-01, months since first order 2: 22.2%Cohort (month of first order) 2011-01, months since first order 3: 19.4%Cohort (month of first order) 2011-01, months since first order 4: 22.2%Cohort (month of first order) 2011-01, months since first order 5: 15.3%Cohort (month of first order) 2011-01, months since first order 6: 15.3%Cohort (month of first order) 2011-01, months since first order 7: 12.5%Cohort (month of first order) 2011-01, months since first order 8: 11.1%Cohort (month of first order) 2011-01, months since first order 9: 20.8%Cohort (month of first order) 2011-01, months since first order 10: 25.0%Cohort (month of first order) 2011-01, months since first order 11: no dataCohort (month of first order) 2011-01, months since first order 12: no dataCohort (month of first order) 2011-01, months since first order 13: no dataCohort (month of first order) 2011-01, months since first order 14: no dataCohort (month of first order) 2011-01, months since first order 15: no dataCohort (month of first order) 2011-01, months since first order 16: no dataCohort (month of first order) 2011-01, months since first order 17: no dataCohort (month of first order) 2011-01, months since first order 18: no dataCohort (month of first order) 2011-01, months since first order 19: no dataCohort (month of first order) 2011-01, months since first order 20: no dataCohort (month of first order) 2011-01, months since first order 21: no dataCohort (month of first order) 2011-01, months since first order 22: no dataCohort (month of first order) 2011-01, months since first order 23: no dataCohort (month of first order) 2011-01, months since first order 24: no data2011-02Cohort (month of first order) 2011-02, months since first order 1: 16.0%Cohort (month of first order) 2011-02, months since first order 2: 16.0%Cohort (month of first order) 2011-02, months since first order 3: 18.4%Cohort (month of first order) 2011-02, months since first order 4: 21.6%Cohort (month of first order) 2011-02, months since first order 5: 16.0%Cohort (month of first order) 2011-02, months since first order 6: 16.0%Cohort (month of first order) 2011-02, months since first order 7: 15.2%Cohort (month of first order) 2011-02, months since first order 8: 15.2%Cohort (month of first order) 2011-02, months since first order 9: 18.4%Cohort (month of first order) 2011-02, months since first order 10: no dataCohort (month of first order) 2011-02, months since first order 11: no dataCohort (month of first order) 2011-02, months since first order 12: no dataCohort (month of first order) 2011-02, months since first order 13: no dataCohort (month of first order) 2011-02, months since first order 14: no dataCohort (month of first order) 2011-02, months since first order 15: no dataCohort (month of first order) 2011-02, months since first order 16: no dataCohort (month of first order) 2011-02, months since first order 17: no dataCohort (month of first order) 2011-02, months since first order 18: no dataCohort (month of first order) 2011-02, months since first order 19: no dataCohort (month of first order) 2011-02, months since first order 20: no dataCohort (month of first order) 2011-02, months since first order 21: no dataCohort (month of first order) 2011-02, months since first order 22: no dataCohort (month of first order) 2011-02, months since first order 23: no dataCohort (month of first order) 2011-02, months since first order 24: no data2011-03Cohort (month of first order) 2011-03, months since first order 1: 17.9%Cohort (month of first order) 2011-03, months since first order 2: 21.8%Cohort (month of first order) 2011-03, months since first order 3: 20.1%Cohort (month of first order) 2011-03, months since first order 4: 22.3%Cohort (month of first order) 2011-03, months since first order 5: 15.1%Cohort (month of first order) 2011-03, months since first order 6: 20.7%Cohort (month of first order) 2011-03, months since first order 7: 20.1%Cohort (month of first order) 2011-03, months since first order 8: 24.0%Cohort (month of first order) 2011-03, months since first order 9: no dataCohort (month of first order) 2011-03, months since first order 10: no dataCohort (month of first order) 2011-03, months since first order 11: no dataCohort (month of first order) 2011-03, months since first order 12: no dataCohort (month of first order) 2011-03, months since first order 13: no dataCohort (month of first order) 2011-03, months since first order 14: no dataCohort (month of first order) 2011-03, months since first order 15: no dataCohort (month of first order) 2011-03, months since first order 16: no dataCohort (month of first order) 2011-03, months since first order 17: no dataCohort (month of first order) 2011-03, months since first order 18: no dataCohort (month of first order) 2011-03, months since first order 19: no dataCohort (month of first order) 2011-03, months since first order 20: no dataCohort (month of first order) 2011-03, months since first order 21: no dataCohort (month of first order) 2011-03, months since first order 22: no dataCohort (month of first order) 2011-03, months since first order 23: no dataCohort (month of first order) 2011-03, months since first order 24: no data2011-04Cohort (month of first order) 2011-04, months since first order 1: 24.5%Cohort (month of first order) 2011-04, months since first order 2: 19.8%Cohort (month of first order) 2011-04, months since first order 3: 19.8%Cohort (month of first order) 2011-04, months since first order 4: 17.9%Cohort (month of first order) 2011-04, months since first order 5: 23.6%Cohort (month of first order) 2011-04, months since first order 6: 17.9%Cohort (month of first order) 2011-04, months since first order 7: 25.5%Cohort (month of first order) 2011-04, months since first order 8: no dataCohort (month of first order) 2011-04, months since first order 9: no dataCohort (month of first order) 2011-04, months since first order 10: no dataCohort (month of first order) 2011-04, months since first order 11: no dataCohort (month of first order) 2011-04, months since first order 12: no dataCohort (month of first order) 2011-04, months since first order 13: no dataCohort (month of first order) 2011-04, months since first order 14: no dataCohort (month of first order) 2011-04, months since first order 15: no dataCohort (month of first order) 2011-04, months since first order 16: no dataCohort (month of first order) 2011-04, months since first order 17: no dataCohort (month of first order) 2011-04, months since first order 18: no dataCohort (month of first order) 2011-04, months since first order 19: no dataCohort (month of first order) 2011-04, months since first order 20: no dataCohort (month of first order) 2011-04, months since first order 21: no dataCohort (month of first order) 2011-04, months since first order 22: no dataCohort (month of first order) 2011-04, months since first order 23: no dataCohort (month of first order) 2011-04, months since first order 24: no data2011-05Cohort (month of first order) 2011-05, months since first order 1: 23.4%Cohort (month of first order) 2011-05, months since first order 2: 24.3%Cohort (month of first order) 2011-05, months since first order 3: 16.2%Cohort (month of first order) 2011-05, months since first order 4: 21.6%Cohort (month of first order) 2011-05, months since first order 5: 20.7%Cohort (month of first order) 2011-05, months since first order 6: 26.1%Cohort (month of first order) 2011-05, months since first order 7: no dataCohort (month of first order) 2011-05, months since first order 8: no dataCohort (month of first order) 2011-05, months since first order 9: no dataCohort (month of first order) 2011-05, months since first order 10: no dataCohort (month of first order) 2011-05, months since first order 11: no dataCohort (month of first order) 2011-05, months since first order 12: no dataCohort (month of first order) 2011-05, months since first order 13: no dataCohort (month of first order) 2011-05, months since first order 14: no dataCohort (month of first order) 2011-05, months since first order 15: no dataCohort (month of first order) 2011-05, months since first order 16: no dataCohort (month of first order) 2011-05, months since first order 17: no dataCohort (month of first order) 2011-05, months since first order 18: no dataCohort (month of first order) 2011-05, months since first order 19: no dataCohort (month of first order) 2011-05, months since first order 20: no dataCohort (month of first order) 2011-05, months since first order 21: no dataCohort (month of first order) 2011-05, months since first order 22: no dataCohort (month of first order) 2011-05, months since first order 23: no dataCohort (month of first order) 2011-05, months since first order 24: no data2011-06Cohort (month of first order) 2011-06, months since first order 1: 23.1%Cohort (month of first order) 2011-06, months since first order 2: 21.3%Cohort (month of first order) 2011-06, months since first order 3: 26.9%Cohort (month of first order) 2011-06, months since first order 4: 20.4%Cohort (month of first order) 2011-06, months since first order 5: 27.8%Cohort (month of first order) 2011-06, months since first order 6: no dataCohort (month of first order) 2011-06, months since first order 7: no dataCohort (month of first order) 2011-06, months since first order 8: no dataCohort (month of first order) 2011-06, months since first order 9: no dataCohort (month of first order) 2011-06, months since first order 10: no dataCohort (month of first order) 2011-06, months since first order 11: no dataCohort (month of first order) 2011-06, months since first order 12: no dataCohort (month of first order) 2011-06, months since first order 13: no dataCohort (month of first order) 2011-06, months since first order 14: no dataCohort (month of first order) 2011-06, months since first order 15: no dataCohort (month of first order) 2011-06, months since first order 16: no dataCohort (month of first order) 2011-06, months since first order 17: no dataCohort (month of first order) 2011-06, months since first order 18: no dataCohort (month of first order) 2011-06, months since first order 19: no dataCohort (month of first order) 2011-06, months since first order 20: no dataCohort (month of first order) 2011-06, months since first order 21: no dataCohort (month of first order) 2011-06, months since first order 22: no dataCohort (month of first order) 2011-06, months since first order 23: no dataCohort (month of first order) 2011-06, months since first order 24: no data2011-07Cohort (month of first order) 2011-07, months since first order 1: 20.8%Cohort (month of first order) 2011-07, months since first order 2: 29.7%Cohort (month of first order) 2011-07, months since first order 3: 27.7%Cohort (month of first order) 2011-07, months since first order 4: 34.7%Cohort (month of first order) 2011-07, months since first order 5: no dataCohort (month of first order) 2011-07, months since first order 6: no dataCohort (month of first order) 2011-07, months since first order 7: no dataCohort (month of first order) 2011-07, months since first order 8: no dataCohort (month of first order) 2011-07, months since first order 9: no dataCohort (month of first order) 2011-07, months since first order 10: no dataCohort (month of first order) 2011-07, months since first order 11: no dataCohort (month of first order) 2011-07, months since first order 12: no dataCohort (month of first order) 2011-07, months since first order 13: no dataCohort (month of first order) 2011-07, months since first order 14: no dataCohort (month of first order) 2011-07, months since first order 15: no dataCohort (month of first order) 2011-07, months since first order 16: no dataCohort (month of first order) 2011-07, months since first order 17: no dataCohort (month of first order) 2011-07, months since first order 18: no dataCohort (month of first order) 2011-07, months since first order 19: no dataCohort (month of first order) 2011-07, months since first order 20: no dataCohort (month of first order) 2011-07, months since first order 21: no dataCohort (month of first order) 2011-07, months since first order 22: no dataCohort (month of first order) 2011-07, months since first order 23: no dataCohort (month of first order) 2011-07, months since first order 24: no data2011-08Cohort (month of first order) 2011-08, months since first order 1: 26.2%Cohort (month of first order) 2011-08, months since first order 2: 29.9%Cohort (month of first order) 2011-08, months since first order 3: 26.2%Cohort (month of first order) 2011-08, months since first order 4: no dataCohort (month of first order) 2011-08, months since first order 5: no dataCohort (month of first order) 2011-08, months since first order 6: no dataCohort (month of first order) 2011-08, months since first order 7: no dataCohort (month of first order) 2011-08, months since first order 8: no dataCohort (month of first order) 2011-08, months since first order 9: no dataCohort (month of first order) 2011-08, months since first order 10: no dataCohort (month of first order) 2011-08, months since first order 11: no dataCohort (month of first order) 2011-08, months since first order 12: no dataCohort (month of first order) 2011-08, months since first order 13: no dataCohort (month of first order) 2011-08, months since first order 14: no dataCohort (month of first order) 2011-08, months since first order 15: no dataCohort (month of first order) 2011-08, months since first order 16: no dataCohort (month of first order) 2011-08, months since first order 17: no dataCohort (month of first order) 2011-08, months since first order 18: no dataCohort (month of first order) 2011-08, months since first order 19: no dataCohort (month of first order) 2011-08, months since first order 20: no dataCohort (month of first order) 2011-08, months since first order 21: no dataCohort (month of first order) 2011-08, months since first order 22: no dataCohort (month of first order) 2011-08, months since first order 23: no dataCohort (month of first order) 2011-08, months since first order 24: no data2011-09Cohort (month of first order) 2011-09, months since first order 1: 27.1%Cohort (month of first order) 2011-09, months since first order 2: 37.8%Cohort (month of first order) 2011-09, months since first order 3: no dataCohort (month of first order) 2011-09, months since first order 4: no dataCohort (month of first order) 2011-09, months since first order 5: no dataCohort (month of first order) 2011-09, months since first order 6: no dataCohort (month of first order) 2011-09, months since first order 7: no dataCohort (month of first order) 2011-09, months since first order 8: no dataCohort (month of first order) 2011-09, months since first order 9: no dataCohort (month of first order) 2011-09, months since first order 10: no dataCohort (month of first order) 2011-09, months since first order 11: no dataCohort (month of first order) 2011-09, months since first order 12: no dataCohort (month of first order) 2011-09, months since first order 13: no dataCohort (month of first order) 2011-09, months since first order 14: no dataCohort (month of first order) 2011-09, months since first order 15: no dataCohort (month of first order) 2011-09, months since first order 16: no dataCohort (month of first order) 2011-09, months since first order 17: no dataCohort (month of first order) 2011-09, months since first order 18: no dataCohort (month of first order) 2011-09, months since first order 19: no dataCohort (month of first order) 2011-09, months since first order 20: no dataCohort (month of first order) 2011-09, months since first order 21: no dataCohort (month of first order) 2011-09, months since first order 22: no dataCohort (month of first order) 2011-09, months since first order 23: no dataCohort (month of first order) 2011-09, months since first order 24: no data2011-10Cohort (month of first order) 2011-10, months since first order 1: 31.7%Cohort (month of first order) 2011-10, months since first order 2: no dataCohort (month of first order) 2011-10, months since first order 3: no dataCohort (month of first order) 2011-10, months since first order 4: no dataCohort (month of first order) 2011-10, months since first order 5: no dataCohort (month of first order) 2011-10, months since first order 6: no dataCohort (month of first order) 2011-10, months since first order 7: no dataCohort (month of first order) 2011-10, months since first order 8: no dataCohort (month of first order) 2011-10, months since first order 9: no dataCohort (month of first order) 2011-10, months since first order 10: no dataCohort (month of first order) 2011-10, months since first order 11: no dataCohort (month of first order) 2011-10, months since first order 12: no dataCohort (month of first order) 2011-10, months since first order 13: no dataCohort (month of first order) 2011-10, months since first order 14: no dataCohort (month of first order) 2011-10, months since first order 15: no dataCohort (month of first order) 2011-10, months since first order 16: no dataCohort (month of first order) 2011-10, months since first order 17: no dataCohort (month of first order) 2011-10, months since first order 18: no dataCohort (month of first order) 2011-10, months since first order 19: no dataCohort (month of first order) 2011-10, months since first order 20: no dataCohort (month of first order) 2011-10, months since first order 21: no dataCohort (month of first order) 2011-10, months since first order 22: no dataCohort (month of first order) 2011-10, months since first order 23: no dataCohort (month of first order) 2011-10, months since first order 24: no data2011-11Cohort (month of first order) 2011-11, months since first order 1: no dataCohort (month of first order) 2011-11, months since first order 2: no dataCohort (month of first order) 2011-11, months since first order 3: no dataCohort (month of first order) 2011-11, months since first order 4: no dataCohort (month of first order) 2011-11, months since first order 5: no dataCohort (month of first order) 2011-11, months since first order 6: no dataCohort (month of first order) 2011-11, months since first order 7: no dataCohort (month of first order) 2011-11, months since first order 8: no dataCohort (month of first order) 2011-11, months since first order 9: no dataCohort (month of first order) 2011-11, months since first order 10: no dataCohort (month of first order) 2011-11, months since first order 11: no dataCohort (month of first order) 2011-11, months since first order 12: no dataCohort (month of first order) 2011-11, months since first order 13: no dataCohort (month of first order) 2011-11, months since first order 14: no dataCohort (month of first order) 2011-11, months since first order 15: no dataCohort (month of first order) 2011-11, months since first order 16: no dataCohort (month of first order) 2011-11, months since first order 17: no dataCohort (month of first order) 2011-11, months since first order 18: no dataCohort (month of first order) 2011-11, months since first order 19: no dataCohort (month of first order) 2011-11, months since first order 20: no dataCohort (month of first order) 2011-11, months since first order 21: no dataCohort (month of first order) 2011-11, months since first order 22: no dataCohort (month of first order) 2011-11, months since first order 23: no dataCohort (month of first order) 2011-11, months since first order 24: no data2011-12Cohort (month of first order) 2011-12, months since first order 1: no dataCohort (month of first order) 2011-12, months since first order 2: no dataCohort (month of first order) 2011-12, months since first order 3: no dataCohort (month of first order) 2011-12, months since first order 4: no dataCohort (month of first order) 2011-12, months since first order 5: no dataCohort (month of first order) 2011-12, months since first order 6: no dataCohort (month of first order) 2011-12, months since first order 7: no dataCohort (month of first order) 2011-12, months since first order 8: no dataCohort (month of first order) 2011-12, months since first order 9: no dataCohort (month of first order) 2011-12, months since first order 10: no dataCohort (month of first order) 2011-12, months since first order 11: no dataCohort (month of first order) 2011-12, months since first order 12: no dataCohort (month of first order) 2011-12, months since first order 13: no dataCohort (month of first order) 2011-12, months since first order 14: no dataCohort (month of first order) 2011-12, months since first order 15: no dataCohort (month of first order) 2011-12, months since first order 16: no dataCohort (month of first order) 2011-12, months since first order 17: no dataCohort (month of first order) 2011-12, months since first order 18: no dataCohort (month of first order) 2011-12, months since first order 19: no dataCohort (month of first order) 2011-12, months since first order 20: no dataCohort (month of first order) 2011-12, months since first order 21: no dataCohort (month of first order) 2011-12, months since first order 22: no dataCohort (month of first order) 2011-12, months since first order 23: no dataCohort (month of first order) 2011-12, months since first order 24: no data
Retention triangle: percent of each monthly customer cohort ordering again in each of the following 23 months, December 2009 to November 2011
Cohort (month of first order)123456789101112131415161718192021222324
2009-12 (and earlier)35.0%33.3%42.5%37.9%36.0%37.6%34.4%33.8%36.2%42.2%49.6%37.6%28.2%24.4%30.3%26.3%30.3%28.4%25.9%25.4%31.3%30.4%40.6%—
2010-0121.5%32.1%31.5%27.2%31.0%26.9%23.4%28.5%32.6%31.0%17.9%22.8%17.9%19.6%15.2%24.5%20.4%19.3%20.1%25.3%19.8%25.3%——
2010-0223.5%22.7%29.3%24.5%19.7%19.2%28.8%25.6%27.7%11.5%12.5%15.2%17.6%12.3%20.0%16.0%16.3%14.4%22.9%22.9%16.5%———
2010-0319.0%23.1%24.3%23.1%20.4%24.7%30.6%27.7%10.9%11.6%14.5%20.0%16.3%20.0%17.0%17.5%15.6%17.7%20.4%21.3%————
2010-0419.0%19.0%16.0%18.4%22.1%27.6%26.5%10.5%10.9%7.5%13.9%14.3%15.6%15.6%15.6%13.9%15.0%18.0%22.8%—————
2010-0515.7%16.9%17.6%17.6%25.5%21.2%12.5%5.9%8.2%11.4%13.3%15.3%15.3%9.8%12.5%13.7%16.5%15.3%——————
2010-0617.6%18.7%20.6%23.2%28.5%12.7%9.0%8.2%11.2%10.5%13.9%15.0%12.4%11.2%12.4%13.1%20.2%———————
2010-0715.7%18.4%29.7%29.2%14.1%11.4%14.6%14.6%11.4%13.5%14.6%13.0%13.5%19.5%17.3%23.8%————————
2010-0819.6%28.8%32.5%16.6%11.7%9.8%12.9%13.5%12.9%12.9%11.7%14.7%17.2%17.2%19.6%—————————
2010-0923.0%23.4%13.0%8.8%10.5%13.8%9.6%13.0%13.0%12.1%10.0%22.6%16.7%16.7%——————————
2010-1025.9%14.7%12.5%8.8%8.3%13.1%13.9%10.7%9.3%10.7%12.8%19.2%23.2%———————————
2010-1117.5%9.5%9.5%7.7%8.9%12.9%10.1%8.6%9.2%11.0%14.7%25.2%————————————
2010-129.2%5.3%9.2%11.8%6.6%5.3%9.2%5.3%2.6%9.2%19.7%—————————————
2011-0116.7%22.2%19.4%22.2%15.3%15.3%12.5%11.1%20.8%25.0%——————————————
2011-0216.0%16.0%18.4%21.6%16.0%16.0%15.2%15.2%18.4%———————————————
2011-0317.9%21.8%20.1%22.3%15.1%20.7%20.1%24.0%————————————————
2011-0424.5%19.8%19.8%17.9%23.6%17.9%25.5%—————————————————
2011-0523.4%24.3%16.2%21.6%20.7%26.1%——————————————————
2011-0623.1%21.3%26.9%20.4%27.8%———————————————————
2011-0720.8%29.7%27.7%34.7%————————————————————
2011-0826.2%29.9%26.2%—————————————————————
2011-0927.1%37.8%——————————————————————
2011-1031.7%———————————————————————
2011-11————————————————————————
2011-12————————————————————————
Share of each cohort (customers grouped by the month of their first order) who ordered again in each later month, in percent. Grey cells are months the data does not reach. The top row is inflated: December 2009 is the first month in the data, so it includes every customer who was already buying (951 of them, against an average of 299 for the next eleven cohorts), and 35% of them ordered again in January, against 20% for the cohorts that follow.SourceUCI Online Retail II, sale lines with a customer id, December 2009 to November 2011
Querychapters/13-shop-cohorts/pipeline/20_model.sqlShow SQL
20_model.sqlSQL
SELECT c.cohort, date_diff('month', c.cohort, o.month) AS month_offset,
       count(DISTINCT o.customer) AS active
FROM orders o JOIN customers c USING (customer)
GROUP BY ALL;

325 cohort-monthsRuns at build time in DuckDB 2.0; shown for reading.Open file

What the workbook holds

The shop is a UK-based online retailer of gifts and homewares whose customers are, in the dataset's description, mostly wholesalers. Each line has an invoice number (a leading C marks a cancellation), a stock code, a description, a quantity, the invoice date and time, a unit price in pounds sterling, a customer id and the customer's country. UCI first published the second year alone as "Online Retail" (id 352), which most tutorials use; this release adds the first year.

From workbook to cohort table

  1. Read both sheets as text

    read_xlsx takes one sheet per call. The Invoice column holds numbers (489434) and text (C489449), so type detection fails on the first cancellation; reading every cell as text and casting afterward avoids that. Dates then arrive as Excel serial numbers, days since 30 December 1899.

    10_stage.sqlSQL
    CREATE OR REPLACE MACRO excel_ts(serial) AS
      TIMESTAMP '1899-12-30' + to_milliseconds(round(serial::DOUBLE * 86400000)::BIGINT);
    
    SELECT 'Year 2009-2010' AS sheet, * FROM sheet('Year 2009-2010')
    UNION ALL
    SELECT 'Year 2010-2011' AS sheet, * FROM sheet('Year 2010-2011');

    525,461 + 541,910 rowschapters/13-shop-cohorts/pipeline/10_stage.sql

  2. Remove the overlap between the sheets

    The second sheet starts on 1 December 2010 and the first ends on 9 December, so nine days are in both. EXCEPT ALL removes from the second sheet only the lines the first already has, counting duplicates, so two identical lines on one invoice stay two lines.

    10_stage.sqlSQL
    SELECT * EXCLUDE (sheet) FROM raw_lines WHERE sheet = 'Year 2009-2010'
    UNION ALL
    (SELECT * EXCLUDE (sheet) FROM raw_lines WHERE sheet = 'Year 2010-2011'
     EXCEPT ALL
     SELECT * EXCLUDE (sheet) FROM raw_lines WHERE sheet = 'Year 2009-2010');

    22,523 rows removed, 1,044,848 keptchapters/13-shop-cohorts/pipeline/10_stage.sql

  3. Label every line before counting anything

    A cohort table should count sales only. Cancellations, postage and fees, stock write-offs (zero price) and lines without a customer id are labelled and kept out of it.

    10_stage.sqlSQL
    CASE WHEN invoice LIKE 'C%' THEN 'cancellation'
         WHEN invoice LIKE 'A%' THEN 'bad-debt adjustment'
         WHEN NOT is_product(sku) THEN 'postage, fee or manual entry'
         WHEN qty <= 0 OR price <= 0 THEN 'stock adjustment'
         WHEN customer IS NULL THEN 'sale, no customer id'
         ELSE 'sale' END AS kind

    6 kindschapters/13-shop-cohorts/pipeline/10_stage.sql

  4. Score customers with NTILE

    RFM scoring ranks customers into fifths by recency, frequency and money spent, using ntile(5) over each measure.

    20_model.sqlSQL
    SELECT customer, ntile(5) OVER (ORDER BY last_ts) AS r,
           ntile(5) OVER (ORDER BY orders, revenue) AS f,
           ntile(5) OVER (ORDER BY revenue) AS m
    FROM customers;

    5 segmentschapters/13-shop-cohorts/pipeline/20_model.sql

Of all lines, 75% are sales with a customer, worth £17.1 million. Another 22% are sales with no customer id, worth £2.6 million; they cannot be put in a cohort, so every rate below is for identified customers. Cancellations total £1.5 million.

How fast customers come back

Repeat rates fall to 13% by month 10 and rise in month 12, when last year's Christmas buyers return

Share of a cohort ordering in each month after the first, pooled over cohorts from January 2010 onward that are observed for that month; the band spans the lowest and highest cohort. Month 12 averages 18% against 14% in month 11. Later months rest on fewer cohorts (1 in month 22).SourceUCI Online Retail II, January 2010 to November 2011

Monthly repeat rates understate how many customers return eventually, because a customer who orders every quarter is active in only one month of three. Counting any return, 20% of new customers ordered again within 30 days, 43% within 90 and 71% within a year, among the 3,334 who were first seen at least a year before the data ends. For those who came back within the year, the median wait was 64 days.

Revenue rests on customers who came back

In 2011 the shop held revenue flat on half as many new customers

Monthly sales to identified customers, in thousands of pounds, split by whether the customer had ordered in an earlier month. From January to November, new customers numbered 3,288 in 2010 and 1,509 in 2011; sales were £7.68 million and £7.68 million. December 2009 counts every customer as new, and December 2011 (nine days) is left off.SourceUCI Online Retail II, sale lines with a customer id

Every November is the peak month, as retailers stock up for Christmas. The second autumn's peak came almost entirely from customers who already knew the shop: returning customers were 91% of January-to-November sales in 2011, against 80% in 2010. The data cannot say whether fewer businesses found the shop or the shop spent less on finding them.

The top 10% of customers account for 64% of revenue

Cumulative share of revenue against cumulative share of customers, ranked from largest to smallest, in percent. The top 1% of customers bought 32% of everything and the top 20% bought 77%. The 72% of customers with more than one order account for 97% of revenue.SourceUCI Online Retail II, December 2009 to December 2011

Who to call: recent, frequent and lapsing customers

RFM segments turn the same table into a list of actions. On 10 December 2011, the day after the last invoice, customers who are both recent and frequent (top two fifths on each) are 25% of customers and 69% of revenue. The segment worth a call is the 349 customers who ordered often (a median of 6 orders) but not for a median of 334 days; they bought 6% of everything.

The 25% of customers who are recent and frequent bought 69% of everything

Best: recent and frequent1,47025%69%1710
Middle2,06735%20%973
At risk: frequent, gone quiet3496%6%3346
Lapsed: rare and long ago1,52526%3%4331
New or occasional, recent4418%1%261
5 rows
RFM segments on 10 December 2011. Recency, frequency and spending are each split into fifths with ntile(5); best means top two fifths on recency and frequency, at risk means top two on frequency and bottom two on recency, and so on. Click a header to sort.SourceUCI Online Retail II, December 2009 to December 2011

Explore the shop's books yourself

The dashboard below runs the chapter's data in your browser. The pipeline writes three Parquet extracts (every order with its customer's cohort and country, the customer list, and sales by year, country and product) to public storage, 1.2 MB in all, and DuckDB-Wasm reads them over HTTP range requests. Pick a country and the retention triangle, revenue split and rankings are recomputed from the orders. Every panel shows its SQL. The Ask box at the bottom hands your question to an AI model that writes the SQL; the query runs here, on the same files, and the model only sees the small result. Its answers are live and unaudited, unlike the numbers above.

Live · runs in your browser

An online shop's customers, December 2009 to December 2011

Engine
DuckDB 2.0.1 · Wasm
Data read
0 B of 1.1 MB

The chapter's data sits in 3 Parquet files on public storage, 1.1 MB in all. Start the engine and DuckDB runs inside this page: each chart below is a SQL query that reads only the row groups and columns it needs over HTTP range requests.

  • ordersEvery order: customer, time, cohort, country, amount
  • customersEvery customer: first month, country, orders, revenue
  • productsSales by year, customer country and product

Queries this chapter's published snapshot; the data does not update in real time. No account, nothing uploaded.

Reusing the workflow

Shell
DOWNLOAD=1 bash chapters/13-shop-cohorts/pipeline/run.sh   # two UCI zips, then stage, model, export, checks

A cohort analysis is a few GROUP BYs once the lines are clean, and most of the work is deciding what counts. Read the workbook as text and cast it yourself, remove any overlap between files with EXCEPT ALL so real duplicates survive, label every line instead of filtering silently, and mark the first cohort as censored. Full pipeline: chapters/13-shop-cohorts.