Sub topic 4
Measuring usage with the billing system tables
This chapter assumes you can write SQL, know how DBUs and SKUs relate to cost, and have Unity Catalog enabled. You also need access to the system catalog. An account admin must grant SELECT on the billing schema before other users can query it.
What the billing tables hold
Databricks records every billable event in system tables. Two matter most for cost work:
| Table | What it contains | Use it for |
|---|---|---|
| `system.billing.usage` | One row per usage record, with SKU, quantity, unit, workspace, time range, and tags | Measuring consumption |
| `system.billing.list_prices` | Public list price per SKU, with start and end times | Converting DBUs to money |
Usage rows also carry custom_tags, which holds the tags you set on compute. The next chapter covers tagging in detail.
Step 1: Measure DBUs
Start with raw consumption. This query sums DBUs per day and SKU for the last 30 days.
SELECT
usage_date,
sku_name,
SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_date >= date_sub(current_date(), 30)
AND usage_unit = 'DBU'
GROUP BY usage_date, sku_name
ORDER BY usage_date, dbus DESC;The usage_unit = 'DBU' filter matters. Some SKUs are billed in other units, and adding those to DBUs gives a meaningless number.
Read the result by SKU. A jump in an all-purpose SKU often means interactive clusters are running longer. A jump in a jobs SKU usually means new or larger jobs.
Step 2: Convert DBUs to estimated cost
DBUs alone do not show money. Join usage to list_prices to price each row.
SELECT
u.workspace_id,
u.custom_tags['team'] AS team,
SUM(u.usage_quantity * p.pricing.default) AS estimated_list_cost
FROM system.billing.usage u
JOIN system.billing.list_prices p
ON u.sku_name = p.sku_name
AND u.cloud = p.cloud
AND u.usage_unit = p.usage_unit
AND u.usage_end_time >= p.price_start_time
AND (p.price_end_time IS NULL OR u.usage_end_time < p.price_end_time)
WHERE u.usage_date >= date_sub(current_date(), 30)
GROUP BY u.workspace_id, u.custom_tags['team']
ORDER BY estimated_list_cost DESC;The time conditions in the join are important. Prices change over time. Each usage row must match the price that was in effect when the usage ended. Without the price_start_time and price_end_time checks, a row can match several price versions and be counted more than once.
Know the limits of the estimate
The result is a list-price estimate. It differs from your invoice in two ways:
- It ignores negotiated discounts and commitment pricing.
- It covers only Databricks charges. The cloud provider bills instances, disks, and storage separately, so those costs do not appear here.
Use the estimate to compare teams, spot trends, and rank workloads. Use your cloud provider's billing data for total spend.
Common errors
- Mixing units. Summing all
usage_quantityvalues without filteringusage_unit. - Duplicate rows from the price join. Leaving out the price time-window conditions.
- Missing attribution. Rows with no
teamtag show up asNULL. A largeNULLgroup means tagging is incomplete, which is a finding in itself. - Permission errors. The
systemcatalog is empty or inaccessible until an admin grants access. - Treating recent data as final. Usage records can arrive with a delay, so the latest hours may be incomplete.
Exercise
Your estimated cost query returns about twice the cost you expect for a SKU whose price changed last month. Which part of the query is the likely cause, and what is the fix?
Show answer
The join to list_prices is probably missing or mishandling the time-window conditions, so usage rows match both the old and the new price. Add u.usage_end_time >= p.price_start_time AND (p.price_end_time IS NULL OR u.usage_end_time < p.price_end_time) so each usage row matches exactly one price.
Exercise
A colleague says the estimated cost from the query equals the amount on the monthly invoice. Give two reasons the numbers can differ.
Show answer
The query uses list prices, so it ignores negotiated discounts. It also excludes cloud provider charges for instances, disks, and storage, which are billed separately from Databricks.