For this project, our primary goal was to identify recurring customers over the last two years and understand their purchasing behavior to help drive retention. We began by exploring the 17 tables that make up the CBSC database. While this initial exploration gave us some direction, we quickly realized we needed more clarity on the specific business motivations behind the analysis. Before diving into implementation, we outlined several potential lines of inquiry to discuss with our stakeholder.


When we met with our stakeholder, they explained that the business had limited visibility into its repeat buyers and wanted to use these insights to improve retention. Although the database contained 10 years of records, they asked us to narrow our focus to the past two years. They also defined a clear hierarchy of priorities:

  1. Primary task: Identify who the recurring customers are.
  2. Secondary task: Determine what kinds of products they buy.
  3. Stretch goal: Analyze when they tend to buy (such as during promotions vs. standard periods), time permitting.

To align on this scope, we identified key source tables and built a sunbeam diagram centered on "number of recurring customers," with each spoke representing the 7Ws.


Next, we refined the sunbeam diagram by mapping relevant fields to each spoke and attribute. Using this as a blueprint, we identified the exact fields we needed to pull and designed a set of streamlined tables:

  • Revised Customers Table: Mapped each customer’s orders alongside the associated products.
  • Recurring Customers Table: Served as our primary table for answering the core business question, containing each customer_id and their total order count over the two-year window.
  • Cleaned Products Table: Combined the product_dimensions and sales tables to include the order date and key product details like product_name. Denormalizing this data made it much faster to query and analyze downstream in tools like Tableau.

We then built these tables in Snowflake using SQL files. Because we were pulling fields from existing tables, we relied on aliased subqueries (AS) to structure the outputs. For example, here is how we created the new products table from the existing sales data:

SQL
CREATE TABLE DSNY14_Products_XM  AS 
    select distinct product_id, products, rrp, fragrance
    from price_table;


ALTER TABLE dsny14_products_xm
RENAME COLUMN rrp TO price;

select * from dsny14_products_xm;

To identify our recurring base, we queried the sales table for customers with more than two orders over the last two years. We discovered that most customers far exceeded this threshold—some had placed more than 500 or even 1,000 orders. Rather than simply flagging repeat buyers, we realized we could segment them into a tier system based on order volume to highlight the business's most loyal clientele. Because order counts spanned such a wide range, we created five numbered tiers, with Tier 1 representing the highest-volume buyers. Using numbers allows the CBSC team to easily attach a dimension table later to assign custom tier names.

SQL
create table cbsc.chin_and_beards.dsny14_recurring_customers_xm as
with cte as (
    select customer_id, count(distinct order_id) as total_orders
    from cbsc.chin_and_beards.sales
    where year(to_date(order_date, 'DD/MM/YYYY')) >= 2108
    group by customer_id
    having total_orders >= 2
)
select c.customer_id, cte.total_orders,
    case
        when cte.total_orders >= 800 then 1
        when cte.total_orders >= 600 then 2
        when cte.total_orders >= 400 then 3
        when cte.total_orders >= 200 then 4
        else 5
    end as customer_tier
from cte
join cbsc.chin_and_beards.customers c
  on cte.customer_id = c.customer_id;
select * from dsny14_recurring_customers_xm;

With customer rankings established, we addressed the first deliverable and shifted to understanding what these customers were buying. We joined our new recurring customers table back to the sales table to rank products by purchase frequency for each buyer. We then narrowed this down to each customer's top three products and added them as columns in the recurring customers table. Pairing a customer's loyalty tier with their top three products gives the team a clear way to target high-value buyers with tailored promotions and marketing.


For visualization, we initially tried connecting Tableau directly to Snowflake, but driver requirements introduced unnecessary complications. Instead, we handled data preparation in Tableau Prep and performed our table joins directly in Tableau. During cleaning, we converted order_date from a string to a proper date format and standardized order_id and customer_id as strings across all tables. We also added an online_orders column to the main customers table, which consolidated product order details with customer contact information like phone numbers and email addresses.


Once the data was prepped, we built several visualizations in Tableau to uncover actionable patterns:

  • All-Time Customer Trend: We tracked order trends across the full timeline and saw a positive upward trajectory in recurring customer volume that eventually peaked and leveled off into a stable plateau.
  • Tier Distribution: A donut chart broke down the exact percentage of recurring customers falling into each of the five loyalty tiers.
  • Store Location Performance: We evaluated the average number of total orders across each store location to compare regional activity.
  • Top Product Order Volume: A box-and-whisker plot of customers' #1 ranked products showed a median order volume of around 7 units, though certain products exhibited wider ranges and significantly more outliers than others.

Finally, we initially planned to analyze total order value using the customers table, but noticed that prices varied for the exact same product. Our stakeholder clarified that these price differences were tied to product size. However, because all sizes of a given item shared the same product_id, we could not reliably map prices to specific sizes. Instead, we pivoted to measuring customer activity by total order quantity rather than revenue. Through this analysis, we uncovered two final data anomalies: every active customer over the past two years qualified as a recurring customer, and three business locations recorded zero orders during that entire timeframe.