What is cost per customer, and how do you measure it in Metabase?
Definition
Cost per customer allocates infrastructure spend to the customers it serves — the foundation of unit economics. Direct costs (dedicated resources, tenant-tagged usage) allocate cleanly; shared platform costs need an explicit distribution rule, and that rule changes the answer.
What data do you need?
- Cost allocated to customers via tags, tenancy mapping, or a cost platform's dimensions
- A documented shared-cost distribution rule (even, usage-based, or revenue-based)
- Usage drivers per customer (requests, storage, compute) for driver-based allocation
- Revenue per customer for margin views
- A stable customer key shared across cost and revenue systems
SQL pattern
WITH direct AS (
SELECT customer_id, SUM(cost_usd) AS direct_cost
FROM customer_cost_allocations
WHERE month = {{month}}
GROUP BY 1
), shared AS (
SELECT SUM(cost_usd) AS shared_cost
FROM shared_platform_costs
WHERE month = {{month}}
), usage AS (
-- Aggregate first: several usage rows per customer would otherwise
-- fan out the join and double-count direct cost.
SELECT customer_id, SUM(usage_units) AS usage_units
FROM customer_usage
WHERE month = {{month}}
GROUP BY 1
), usage_weights AS (
SELECT
customer_id,
1.0 * usage_units / NULLIF(SUM(usage_units) OVER (), 0) AS weight
FROM usage
), customers AS (
-- Every customer with direct cost OR usage, so no shared cost is stranded.
SELECT customer_id FROM direct
UNION
SELECT customer_id FROM usage_weights
)
SELECT
c.customer_id,
ROUND(COALESCE(d.direct_cost, 0), 2) AS direct_cost,
ROUND(s.shared_cost * COALESCE(w.weight, 0), 2) AS shared_cost_allocated,
ROUND(
COALESCE(d.direct_cost, 0) + s.shared_cost * COALESCE(w.weight, 0), 2
) AS total_cost
FROM customers c
LEFT JOIN direct d USING (customer_id)
LEFT JOIN usage_weights w USING (customer_id)
CROSS JOIN shared s
ORDER BY total_cost DESC;Common pitfalls
Where does this metric apply?
This metric commonly uses data from CloudZero, AWS Billing, Google Cloud Billing, Kubecost, plus any warehouse models built on raw billing exports at the same grain.