# How do I calculate my Databricks spend from system tables to compare against SELECT?

URL: https://select.dev/docs/reference/faq/using-select/calculate-databricks-spend-from-system-tables
Index of all SELECT docs: https://select.dev/docs/llms.txt

> How to independently verify SELECT's reported Databricks platform spend using Databricks' own system.billing.usage and system.billing.list_prices tables, including any negotiated discounts.

SELECT reports Databricks platform spend, priced using Databricks' own `system.billing.usage` and `system.billing.list_prices` system tables. You can run the query below directly against your own Databricks workspace to independently verify SELECT's numbers.

This only covers Databricks platform spend. It does not include underlying cloud infrastructure spend (e.g. Azure, AWS, or GCP compute/storage billed directly by the cloud provider), which is a separate cost outside of what SELECT currently reports.

Fill in your `workspace_id` and `account_id` in the `params` CTE, and any negotiated discounts in the `discounts` CTE, then run the query in a Databricks SQL editor connected to your workspace. The total should line up with SELECT's Cost Explorer for the same date range.

```sql
with
-- === fill in below ===
params as (
    select
        '2026-06-01'::date as start_date,
        '2026-06-30'::date as end_date,
        '<your-workspace-id>' as workspace_id,
        '<your-account-id>' as account_id
),
-- add negotiated discounts here; more specific rows win (sku over product over global)
discounts (sku_name, billing_origin_product, discount_pct) as (
    values
        ('<sku-name>', null, 0.00)
    -- (null, '<billing-origin-product>', 0.00)  -- product-level discount
    -- (null, null, 0.00)  -- global discount
),
-- === end fill in ===
global_discount as (
    select discount_pct
    from discounts
    where sku_name is null
        and billing_origin_product is null
),
usage as (
    select
        u.record_id,
        u.account_id,
        u.workspace_id,
        u.sku_name,
        u.cloud,
        u.usage_unit,
        u.usage_date,
        u.usage_quantity,
        u.billing_origin_product
    from
        system.billing.usage as u
        cross join params as p
    where
        u.usage_date >= p.start_date
        and u.usage_date <= p.end_date
        and u.workspace_id = p.workspace_id
        and u.account_id = p.account_id
),
list_prices as (
    select
        account_id,
        sku_name,
        cloud,
        usage_unit,
        pricing ['effective_list'] ['default']::decimal(38, 10) as list_price,
        date_trunc(
            'day',
            timestampadd(second, 10, price_start_time)
        )::date as price_start_date,
        price_end_time::date as price_end_date
    from
        system.billing.list_prices
),
usage_priced as (
    select
        u.account_id,
        u.workspace_id,
        u.sku_name,
        u.billing_origin_product,
        u.usage_date,
        u.usage_quantity,
        lp.list_price,
        coalesce(sku_d.discount_pct, product_d.discount_pct, gd.discount_pct, 0) as discount_pct,
        lp.list_price * (
            1 - coalesce(sku_d.discount_pct, product_d.discount_pct, gd.discount_pct, 0)
        ) as discounted_price
    from
        usage as u
        inner join list_prices as lp on u.account_id = lp.account_id
        and u.sku_name = lp.sku_name
        and u.cloud = lp.cloud
        and u.usage_unit = lp.usage_unit
        and u.usage_date >= lp.price_start_date
        and (
            lp.price_end_date is null
            or u.usage_date < lp.price_end_date
        )
        left join discounts as sku_d on u.sku_name = sku_d.sku_name
        left join discounts as product_d on u.billing_origin_product = product_d.billing_origin_product
        and product_d.sku_name is null
        left join global_discount as gd on true
    -- price windows can overlap; keep only the latest one per usage record
    qualify row_number() over (
        partition by u.record_id
        order by
            lp.price_start_date desc
    ) = 1
)
select
    account_id,
    workspace_id,
    billing_origin_product,
    sku_name,
    sum(usage_quantity * list_price) as total_spend_list_price,
    sum(usage_quantity * discounted_price) as total_spend_discounted
from
    usage_priced
group by
    all
order by
    total_spend_discounted desc;

```
