dwhat

← Guides

BigQuery and Snowflake

Why did my BigQuery or Snowflake bill go up?

A bill that went up went up on particular days, because of particular queries. Two queries find them: one that puts every day next to the median of the fourteen before it, and one that splits the day that stands out by who and what ran.

The median, not the average: one earlier bad day would pull an average up and make the next one look normal.

1. Which day jumped

Days are UTC, and a day with no billed queries counts as zero, so the baseline is not flattered by gaps. times_median is how many times its usual a day cost; today is not over yet.

On Snowflake this reads metered credits, idle time included, so the total matches compute on the invoice.

BigQuery: daily cost against its median
-- Each UTC day of the last 30 against the median of the 14 days before it.
WITH days AS (
  SELECT day
  FROM UNNEST(GENERATE_DATE_ARRAY(DATE_SUB(CURRENT_DATE(), INTERVAL 44 DAY), CURRENT_DATE())) AS day
),
billed AS (
  SELECT
    DATE(creation_time) AS day,
    SUM(total_bytes_billed) / POW(1024, 4) * 6.25 AS cost
  FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
  WHERE creation_time >= TIMESTAMP(DATE_SUB(CURRENT_DATE(), INTERVAL 44 DAY))
    AND job_type = 'QUERY' AND state = 'DONE'
    AND IFNULL(statement_type, '') != 'SCRIPT'
    AND (IFNULL(total_bytes_billed, 0) > 0 OR IFNULL(total_slot_ms, 0) > 0)
  GROUP BY day
),
daily AS (
  SELECT day, IFNULL(cost, 0) AS cost
  FROM days LEFT JOIN billed USING (day)
),
compared AS (
  SELECT
    d.day,
    d.cost,
    PERCENTILE_CONT(b.cost, 0.5) OVER (PARTITION BY d.day) AS baseline,
    ROW_NUMBER() OVER (PARTITION BY d.day) AS n
  FROM daily d
  JOIN daily b
    ON b.day BETWEEN DATE_SUB(d.day, INTERVAL 14 DAY) AND DATE_SUB(d.day, INTERVAL 1 DAY)
)
SELECT
  day,
  ROUND(cost, 2) AS on_demand_usd,
  ROUND(baseline, 2) AS median_14_days_before,
  ROUND(SAFE_DIVIDE(cost, baseline), 1) AS times_median
FROM compared
WHERE n = 1 AND day >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
ORDER BY day DESC
Snowflake: daily cost against its median
-- Each UTC day of the last 30 against the median of the 14 days before it.
-- Metered credits, so idle warehouse time is in the total, as it is on the invoice.
WITH days AS (
  SELECT DATEADD(day, -(ROW_NUMBER() OVER (ORDER BY SEQ4()) - 1),
                 TO_DATE(CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()))) AS day
  FROM TABLE(GENERATOR(ROWCOUNT => 45))
),
metered AS (
  SELECT
    TO_DATE(CONVERT_TIMEZONE('UTC', start_time)) AS day,
    SUM(credits_used_compute) AS credits
  FROM snowflake.account_usage.warehouse_metering_history
  WHERE start_time >= DATEADD(day, -46, CURRENT_TIMESTAMP())
  GROUP BY 1
),
daily AS (
  SELECT days.day, COALESCE(metered.credits, 0) * 3 AS cost
  FROM days LEFT JOIN metered ON metered.day = days.day
)
SELECT
  d.day,
  ROUND(d.cost, 2) AS list_usd,
  ROUND(MEDIAN(b.cost), 2) AS median_14_days_before,
  ROUND(d.cost / NULLIF(MEDIAN(b.cost), 0), 1) AS times_median
FROM daily d
JOIN daily b
  ON b.day BETWEEN DATEADD(day, -14, d.day) AND DATEADD(day, -1, d.day)
GROUP BY d.day, d.cost
HAVING COUNT(*) = 14
ORDER BY d.day DESC

6.25 is BigQuery's on-demand list price per TiB and 3 is the list price per Snowflake credit that dwhat assumes by default. Put the rate on your contract in their place. Change region-us to the region your jobs run in.

See a sample audit: a made-up month with one such day, flagged against the same 14-day median.

Documented in: BigQuery: INFORMATION_SCHEMA.JOBS view · Snowflake: WAREHOUSE_METERING_HISTORY view

2. What grew that day

Put the day in spike_day (it defaults to yesterday). Each row is a user and dbt model with what it cost that day, its daily average over the fourteen days before, and the difference. The top rows are the answer.

The dbt model comes from dbt's query comment; queries without one show as (not dbt).

BigQuery: what grew on the day
-- What grew on one day: cost by user and dbt model, against the 14 days before.
WITH params AS (
  SELECT DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) AS spike_day  -- or DATE '2026-01-31'
),
jobs AS (
  SELECT
    DATE(creation_time) AS day,
    user_email,
    IFNULL(COALESCE(
        REGEXP_EXTRACT(query, r'"node_id": *"([^"]+)"'),
        (SELECT value FROM UNNEST(labels) WHERE key = 'node_id')
      ), '(not dbt)') AS dbt_node,
    total_bytes_billed / POW(1024, 4) * 6.25 AS cost
  FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT, params
  WHERE creation_time >= TIMESTAMP(DATE_SUB(spike_day, INTERVAL 14 DAY))
    AND creation_time < TIMESTAMP(DATE_ADD(spike_day, INTERVAL 1 DAY))
    AND job_type = 'QUERY' AND state = 'DONE'
    AND IFNULL(statement_type, '') != 'SCRIPT'
    AND (IFNULL(total_bytes_billed, 0) > 0 OR IFNULL(total_slot_ms, 0) > 0)
)
SELECT
  user_email,
  dbt_node,
  ROUND(SUM(IF(day = spike_day, cost, 0)), 2) AS on_the_day,
  ROUND(SUM(IF(day < spike_day, cost, 0)) / 14, 2) AS daily_average_before,
  ROUND(SUM(IF(day = spike_day, cost, 0)) - SUM(IF(day < spike_day, cost, 0)) / 14, 2) AS increase
FROM jobs, params
GROUP BY user_email, dbt_node
ORDER BY increase DESC
LIMIT 20
Snowflake: what grew on the day
-- What grew on one day: credits by user, warehouse and dbt model, against the 14 days before.
WITH params AS (
  SELECT DATEADD(day, -1, TO_DATE(CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()))) AS spike_day  -- or '2026-01-31'::DATE
),
attributed AS (
  SELECT
    TO_DATE(CONVERT_TIMEZONE('UTC', a.start_time)) AS day,
    a.user_name,
    a.warehouse_name,
    COALESCE(REGEXP_SUBSTR(q.query_text, '"node_id": *"([^"]+)"', 1, 1, 'e', 1), '(not dbt)') AS dbt_node,
    a.credits_attributed_compute * 3 AS cost
  FROM snowflake.account_usage.query_attribution_history a
  CROSS JOIN params p
  LEFT JOIN snowflake.account_usage.query_history q
    ON q.query_id = a.query_id
   AND q.start_time >= DATEADD(day, -16, p.spike_day)
  -- A day either side, so the UTC days are whole whatever the session's time zone.
  WHERE a.start_time >= DATEADD(day, -15, p.spike_day)
    AND a.start_time < DATEADD(day, 2, p.spike_day)
)
SELECT
  user_name,
  warehouse_name,
  dbt_node,
  ROUND(SUM(IFF(day = spike_day, cost, 0)), 2) AS on_the_day,
  ROUND(SUM(IFF(day BETWEEN DATEADD(day, -14, spike_day) AND DATEADD(day, -1, spike_day), cost, 0)) / 14, 2) AS daily_average_before,
  ROUND(SUM(IFF(day = spike_day, cost, 0))
        - SUM(IFF(day BETWEEN DATEADD(day, -14, spike_day) AND DATEADD(day, -1, spike_day), cost, 0)) / 14, 2) AS increase
FROM attributed, params
GROUP BY user_name, warehouse_name, dbt_node
ORDER BY increase DESC
LIMIT 20

On Snowflake the breakdown is attributed credits, without idle time. If step 1 jumped and nothing here did, a warehouse ran longer or larger with nothing to do: check idle credits by warehouse.

See a sample audit: select the spike day in a made-up BigQuery project and see the users, dbt models and dashboards behind it.

Reconcile Snowflake metering with query credits: in your browser, to see which warehouse and day the unattributed compute is on.

Documented in: Snowflake: QUERY_ATTRIBUTION_HISTORY view · dbt: query-comment

3. When it grew over weeks, not on a day

A bill can climb without one day standing out: a model that went from incremental to a full refresh, a dashboard that refreshes more often. Then compare a period before the change with a period after it, by cost per day, so periods of different lengths compare fairly.

Use whole UTC days on both sides and the same price for both, or the difference is partly arithmetic.

Compare two periods in your browser: one CSV export, and the change per day by user, dbt model and dashboard, with what the export cannot price named.

Estimate a warehouse size or resize before it runs

Gen1 standard warehouse credit rates double at each size step. A larger size only saves compute credits if its runtime falls below the inverse rate ratio; speed is an assumption to test.

Estimate warehouse cost by size and hours: compare monthly compute and the runtime factor needed to break even on a resize.

What this misses

Run this every day instead

dwhat reads the same history with a read-only account, every day. It keeps the daily cost by user, dbt model and dashboard, emails you when a day costs well above its 14-day median and says what grew, and lists the 20 most expensive queries with the fixes above where the evidence supports them.

Connect a read-only account for a free audit

Related guides