Module 16 · Lesson 4 of 10Detailed study · about 22 min

Read metering history and find query-level costs

Use METERING_DAILY_HISTORY, WAREHOUSE_METERING_HISTORY and QUERY_ATTRIBUTION_HISTORY to distinguish billed credits, warehouse idle time and query-level cost attribution.

Follow the credits from a day to a query

Finance sees 8 compute credits on ORDERS_ELT, the warehouse that transforms already-loaded order data. Engineers can attribute 5 of those credits to query execution in the same window. The missing 3 are a reason to inspect warehouse activity. First make sure both numbers cover the same account, UTC interval and type of compute.

A metering view records consumption at a defined level of detail. Start at the service and day to see billed compute. Drill down to a warehouse and hour for running compute. Use query-level attribution for individual statements on standard warehouses. These views overlap, so joining raw rows and adding their totals can count the same consumption twice.

Use a narrower meter as the question gets more specific
QuestionViewWhat to read
How many credits were billed?METERING_DAILY_HISTORYCREDITS_BILLED by UTC date and service
How much warehouse compute ran without attributed work?WAREHOUSE_METERING_HISTORYCompute credits minus attributed query compute for the same warehouse and interval
Which statements used the most execution compute?QUERY_ATTRIBUTION_HISTORYAttributed compute by query ID, with acceleration in a separate column

Explain idle time before assigning it

For a standard warehouse, subtract the hourly credits attributed to queries from compute used in that same hourly metering view. In the sample, 8 − 5 leaves 3 idle credits. Idle includes running compute between work intervals as measured by the meter. Query attribution can include short gaps within an active minute. An Adaptive Warehouse uses QUERY_METERING_HISTORY for per-query credit usage and reports NULL in the hourly attributed column. Keep missing data separate from zero.

On standard warehouses, concurrent statements share compute. Per-query attribution uses resource consumption during shared intervals. A query’s attributed compute credits omit warehouse idle time, and omit storage, transfer and other service charges. Query Acceleration Service credits are available separately when present. Track them without adding them twice to billed service totals.

Use a closed window that is safely behind publication delays. Queries around 100 milliseconds or shorter can be absent from standard query-level attribution. Daily metering can lag by up to three hours, some warehouse attribution columns by up to six hours and standard query attribution by up to eight hours. A query-start window is helpful for finding statements, but long statements can cross its edges. Use hourly metering for the idle split and query history for investigation.

Follow the billing grain from account to query

Grain is what a single row represents. Daily service totals, warehouse hours and individual queries have different grains. Use billed daily service credits to identify the increase. Use an hourly service meter to narrow when it happened. Use the warehouse meter to estimate idle and a query ID to diagnose individual work.

Use a role with access to the required SNOWFLAKE views and an approved analysis warehouse. SNOWFLAKE.USAGE_VIEWER covers warehouse and query attribution, while Query History can require an additional approved role or delegated view. Check the current Account Usage role mapping. Set UTC in a dedicated worksheet and compare closed, matched windows. Never repeat a warehouse-hour total by joining it to every query in that hour.

What one row tells you
ViewTypical grainFields to read
METERING_DAILY_HISTORYDay and serviceCREDITS_BILLED includes Cloud Services adjustment.
METERING_HISTORYHour and metered service/resourceCREDITS_USED is raw usage.
WAREHOUSE_METERING_HISTORYWarehouse hourCREDITS_USED_COMPUTE and CREDITS_ATTRIBUTED_COMPUTE_QUERIES can explain idle.
QUERY_HISTORYQueryEXECUTION_TIME and queue columns are milliseconds. Spill columns are bytes.
QUERY_ATTRIBUTION_HISTORYAttributed standard-warehouse queryExecution credits and separate QAS credits. Use QUERY_METERING_HISTORY for Adaptive Warehouses.
Trace an increase without counting it twice Find the service and warehouse first, then use query rows to explain the warehouse evidence.
  1. Daily billed serviceFind the resource and hours to Warehouse hours or feature meter
  2. Warehouse hours or feature meterFind work in the same window to Query ID and execution credits
  3. Query ID and execution creditsInspect timing, spill and ownership to Query behavior and workload owner

Locate the service hour behind a daily billed increase

Replace the two timestamps with the same complete UTC interval used to check the bill. DATE_TRUNC puts hourly rows in a comparable time bucket. Group by hour and service. If PIPE grows at 02:00 and warehouse usage is steady, inspect the ingest path rather than resizing compute.

SQL · configuration template
ALTER SESSION SET TIMEZONE = 'UTC';
SELECT DATE_TRUNC('hour', start_time) AS utc_hour, service_type,
       SUM(credits_used_compute) AS compute_credits,
       SUM(credits_used_cloud_services) AS cloud_credits_used,
       SUM(credits_used) AS raw_credits
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY
WHERE start_time >= '2026-10-12 00:00:00'::TIMESTAMP_LTZ
  AND start_time < '2026-10-13 00:00:00'::TIMESTAMP_LTZ
GROUP BY utc_hour, service_type ORDER BY utc_hour, raw_credits DESC;

Tie the expensive query to its measured behavior

Replace the ID and UTC window using the top query from the existing worked example. The left join keeps query evidence even when there is no credit row. A representative query with 0.40 execution credits and 0.10 QAS credits shows 0.50 for those two components. A NULL execution credit remains unknown. This total leaves out warehouse idle, Cloud Services, storage and transfer.

The account attribution view can lag by up to eight hours and omits queries at roughly 100 milliseconds or less. Concurrent work is weighted by consumption. A gap within a cluster’s attribution minute can be assigned to queries in that minute. All unused time is not necessarily unassigned. Check that warehouse attribution fields are complete before computing idle.

SQL · configuration template
ALTER SESSION SET TIMEZONE = 'UTC';
SELECT h.query_id, h.user_name, h.warehouse_name, h.query_tag,
       h.execution_time, h.queued_overload_time, h.queued_provisioning_time,
       h.bytes_spilled_to_local_storage, h.bytes_spilled_to_remote_storage,
       a.credits_attributed_compute, a.credits_used_query_acceleration,
       a.credits_attributed_compute + COALESCE(a.credits_used_query_acceleration, 0) AS execution_and_qas
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY h
LEFT JOIN SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY a ON a.query_id = h.query_id
  AND a.start_time >= '2026-10-12'::DATE AND a.start_time < '2026-10-13'::DATE
WHERE h.query_id = '<query_id>'
  AND h.start_time >= '2026-10-12'::DATE AND h.start_time < '2026-10-13'::DATE;

Explain the decision in an interview

Start with the rule, then say what you would check in a real account.

How would you calculate the cost of one query?

I look up the query ID and record its attributed warehouse compute and any separate acceleration credits. Those are useful components. I would not call them the invoice cost of the query.

Where do you measure idle compute?

I subtract attributed execution from compute in the same complete warehouse-hour rows. If attribution is missing, I report the idle split as unavailable and check the warehouse type and latency.

Why can joining billing and query history overstate credits?

Several queries can run in the same billed hour. I keep the hourly total at its own grain, aggregate query evidence separately, and reconcile before allocating any difference.

Words used in this lesson
Metering history
Service consumption measured at a defined time and object level.
Query attribution
Compute credits assigned to execution of a particular query.
Idle credits
Warehouse compute beyond the amount attributed to query work.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Read metering history and find query-level costs

Date and service
Used credits
Billed credits

Start from the billed service

Use daily metering for billed compute credits after the adjustment.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Start from the billed service

    Use daily metering for billed compute credits after the adjustment.

    Date and service → Used credits → Billed credits

  2. Trace warehouse spend

    In hourly metering, 8 compute credits minus 5 attributed query credits leaves 3 idle credits.

    8 compute → 5 attributed → 3 idle

  3. Find query candidates

    Open Query History and Query Profile for a costly query ID, then compare its inputs and result.

    Query ID → Query Profile → Test a change

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Reconcile used and billed credits by service

SQL · runnable example
ALTER SESSION SET TIMEZONE = 'UTC';

SELECT usage_date,
       service_type,
       credits_used,
       credits_adjustment_cloud_services,
       credits_billed
FROM snowflake.account_usage.metering_daily_history
WHERE usage_date >= DATEADD(day, -8, CURRENT_DATE())
  AND usage_date < DATEADD(day, -1, CURRENT_DATE())
ORDER BY usage_date, service_type;

What to expect and why

Use a role with approved access to the Account Usage views. The first statement sets your session time zone to UTC. The UTC window includes seven complete days and skips yesterday to allow for delayed data. For example, a warehouse line with 23.40 used and a −2.00 adjustment shows 21.40 billed. A separate 2.00 billed serverless line would bring that illustrative day to 23.40 billed compute credits.

Split running warehouse compute from query compute

SQL · runnable example
ALTER SESSION SET TIMEZONE = 'UTC';

SELECT warehouse_id,
       MAX(warehouse_name) AS warehouse_name,
       ROUND(SUM(credits_used_compute), 4) AS compute_credits,
       ROUND(SUM(credits_attributed_compute_queries), 4) AS query_credits,
       CASE WHEN COUNT(credits_attributed_compute_queries) = COUNT(*)
         THEN ROUND(SUM(credits_used_compute - credits_attributed_compute_queries), 4)
       END AS idle_credits
FROM snowflake.account_usage.warehouse_metering_history
WHERE start_time >= DATEADD(day, -8, CURRENT_DATE())
  AND start_time < DATEADD(day, -1, CURRENT_DATE())
GROUP BY warehouse_id
ORDER BY compute_credits DESC;

What to expect and why

Group by warehouse ID so a name change does not split one warehouse into two rows. MAX provides a display label, which may be an older name. A complete row with 8 compute and 5 query credits has 3 idle credits. NULL idle signals unavailable attribution and should stay out of the idle ranking.

Find expensive queries on a standard warehouse

SQL · runnable example
ALTER SESSION SET TIMEZONE = 'UTC';

SELECT query_id,
       query_tag,
       credits_attributed_compute,
       COALESCE(credits_used_query_acceleration, 0) AS acceleration_credits
FROM snowflake.account_usage.query_attribution_history
WHERE warehouse_name = 'ORDERS_ELT'
  AND start_time >= DATEADD(day, -8, CURRENT_DATE())
  AND start_time < DATEADD(day, -1, CURRENT_DATE())
ORDER BY credits_attributed_compute DESC NULLS LAST, query_id
LIMIT 20;

What to expect and why

Replace ORDERS_ELT with a known standard warehouse. The 20 rows are leads for Query History and Query Profile, ordered by warehouse execution credits. A query with 0.4 execution and 0.1 acceleration credits shows two separate amounts. The list omits warehouse idle and is a partial list by design.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Which source answers how many compute credits were billed after the daily Cloud Services adjustment?

Try it yourself

Given 14 compute credits and 9.5 attributed in complete warehouse metering, calculate the idle portion and explain what would change if attribution were NULL.

Compare your reasoning

Idle was 4.5 compute credits. With NULL attribution, the idle split is unavailable. Check warehouse type and history availability.

Official sources and curriculum

Module 16 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab