Customer Count View

Computes standardized customer quantity metrics (starting base, movements, net new, and ending balance) over time and by value type.

Purpose

Produce a customer count base view evolution over time.

This model consolidates starting balances, customer movements (new, upsell, downsell, churn), and cumulative effects into a single, standardized dataset that can be reused consistently across reports, dashboards, and analyses.

Business Logic

  • Start from cumulative customer counts provided by customer_count
  • Derive the customer base per period:
    • Current base = previous period ending balance
    • Ending balance = starting balance + cumulative net new
  • Decompose customer movements using revenue_changes:
    • New customers
    • Upsell
    • Downsell
    • Churn
  • All calculations are partitioned by value_type_id and ordered by date
  • Output provides both:
    • Point-in-time customer base
    • Period movements explaining the change

Output Contract

Definitions

ColumnDescription
dateDate represented as YYYY-MM-DD.
value_type_idValue Type identifier.
current_baseCustomer base at the start of the period.
new_customersNumber of new customers acquired in the period.
upsellNumber of customers contributing to upsell movements in the period.
downsellNumber of customers contributing to downsell movements in the period.
churnNumber of customers lost in the period.
net_newNet customer change in the period (new − churn).
ending_balanceCustomer base at the end of the period.

Sample & Implementation

Customer quantity metrics derived from customer counts and revenue changes.
datevalue_type_idcurrent_basenew_customersupselldownsellchurnnet_newending_balance
2025-01-0123000604125353035
2025-02-0123035604113473082
2025-03-0123082604113473129
2025-04-0123129604113473176
2025-05-0123176604113473223
2025-06-0123223604113473270
2025-07-0123270604114463316
2025-08-0123316604114463362
2025-09-0123362604114463408
2025-10-0123408604114463454
{{config(materialized='view')}}


with customer_count as (
    select * from {{ ref('customer_count') }}
),

changes as (
    select * from {{ref('revenue_changes')}}
),

value_types as (
    select * from {{ref('value_types')}}
    ),

new_customers as (
    select
        date,
        value_type_id,
        nr_of_customers
    from changes
    where revenue_type_id = 1
),

upsell_customers as (
    select
        date,
        value_type_id,
        nr_of_customers
    from changes
    where revenue_type_id = 2
),

downsell_customers as (
    select
        date,
        value_type_id,
        nr_of_customers
    from changes
    where revenue_type_id = 3
),

churn_customers as (
    select
        date,
        value_type_id,
        nr_of_customers
    from changes
    where revenue_type_id = 4
)

select
    cc.date,
    vt.name as value_type,
    cc.current_base,
    nc.nr_of_customers as new_customers,
    uc.nr_of_customers as upsell,
    dc.nr_of_customers as downsell,
    chc.nr_of_customers as churn,
    cc.net_new,
    cc.ending_balance
from customer_count cc
left join new_customers nc on nc.date = cc.date and nc.value_type_id = cc.value_type_id
left join upsell_customers uc on uc.date = cc.date and uc.value_type_id = cc.value_type_id
left join downsell_customers dc on dc.date = cc.date and dc.value_type_id = cc.value_type_id
left join churn_customers chc on chc.date = cc.date and chc.value_type_id = cc.value_type_id
left join value_types vt on vt.id = cc.value_type_id

Dependencies

On this page

Star us on GitHub

If you enjoy this content and find it useful, give us a star on GitHub to show your support and stay updated with our latest improvements.