# BigQuery Cost Queries: SQL to Find and Cut BigQuery Spend | Masthead

20 ready-to-run SQL queries for BigQuery cost: the most expensive queries, cost by user, project, label, dbt model and dashboard, slot usage, storage cost, unused and dead-end tables.

> For the index of this section of the site, see [llms.txt](https://mastheadata.com/llms.txt)

Data FinOps

# BigQuery cost queries

Copy, paste, run. Each query reads INFORMATION\_SCHEMA metadata only, answers one cost question, and comes with what to do about the result. Together they are a Data FinOps toolkit for BigQuery.

No query matches. See the [INFORMATION\SCHEMA.JOBS reference](https://mastheadata.com/bigquery/sql/information-schema-jobs.md).

## Where the money goes

Find the queries, users, projects and days that make up the bill.

*   [BigQuery cost by project across the organizationThis query ranks every project in the organization by bytes billed, on-demand cost estimate and slot-hours over the last 30 days, from one INFORMATION\SCHEMA view.](https://mastheadata.com/bigquery/cost-queries/cost-by-project.md)
*   [BigQuery cost by user and service accountThis query adds up bytes billed, an on-demand cost estimate and slot-hours per user and service account over the last 30 days.](https://mastheadata.com/bigquery/cost-queries/cost-by-user.md)
*   [Daily BigQuery cost trend and spike detectionThis query returns BigQuery compute per day for the last 90 days (bytes billed, on-demand cost estimate, slot-hours) and a variation flags days that cost more than twice the previous week's average.](https://mastheadata.com/bigquery/cost-queries/daily-cost-trend.md)
*   [Find the most expensive queries in BigQueryThis query lists the BigQuery jobs that billed the most bytes in the last 30 days, with an on-demand cost estimate, slot-hours and the start of the SQL.](https://mastheadata.com/bigquery/cost-queries/most-expensive-queries.md)
*   [Which BigQuery tables drive query costThis query ranks tables by the bytes billed of the queries that read them over the last 30 days, with an even split for queries that read several tables.](https://mastheadata.com/bigquery/cost-queries/cost-by-table.md)

## Cost attribution

Split compute cost by label, pipeline, dbt model and BI tool, so every dollar has an owner.

*   [BigQuery cost by label: team, product or pipelineThis query splits BigQuery compute by the value of a job label, such as team or cost center, and shows how much spend has no label at all.](https://mastheadata.com/bigquery/cost-queries/cost-by-label.md)
*   [BigQuery cost of Looker Studio dashboardsThis query finds the BigQuery jobs Looker Studio runs, groups them by data source and shows their on-demand cost and cache hit rate over the last 30 days.](https://mastheadata.com/bigquery/cost-queries/looker-studio-cost.md)
*   [BigQuery cost per Airflow DAG and taskThis query uses the airflow-dag and airflow-task labels that Airflow's Google provider adds to BigQuery jobs to rank DAGs and tasks by on-demand cost and slot-hours over the last 30 days, on Cloud Composer or any other Airflow.](https://mastheadata.com/bigquery/cost-queries/airflow-dag-cost.md)
*   [BigQuery cost per dbt modelThis query attributes BigQuery compute to dbt models by reading the JSON comment dbt prepends to every query, then ranks models by on-demand cost, slot-hours and run time over the last 30 days.](https://mastheadata.com/bigquery/cost-queries/dbt-model-cost.md)

## Slots and billing model

Measure slot usage and decide between on-demand and editions per workload.

*   [BigQuery slot usage by hourThis query turns INFORMATION\SCHEMA.JOBS\TIMELINE into the average number of slots your jobs used in each hour of the last week.](https://mastheadata.com/bigquery/cost-queries/slot-usage-by-hour.md)
*   [On-demand vs editions: which is cheaper per projectThis query compares what each project's queries cost on-demand with what the same slot-hours would cost on Standard and Enterprise editions, using 30 days of INFORMATION\SCHEMA data, and adds the GiB scanned per slot-hour that decides the answer.](https://mastheadata.com/bigquery/cost-queries/on-demand-vs-editions.md)
*   [Peak and p95 BigQuery slot usageThis query computes slots in use for every second of the last week from JOBS\TIMELINE, then reports the average, 95th percentile and peak per hour.](https://mastheadata.com/bigquery/cost-queries/peak-slot-usage.md)

## Storage

See what each table and dataset costs to keep, and which billing model is cheaper.

*   [BigQuery storage cost per tableThis query lists the tables that cost the most to store, with logical and physical size and the monthly cost under each billing model, from INFORMATION\SCHEMA.TABLE\STORAGE.](https://mastheadata.com/bigquery/cost-queries/storage-cost-by-table.md)
*   [Find tables paying for time travel and fail-safe storageThis query finds the tables with the most time-travel and fail-safe bytes, which physical storage billing charges at the active rate.](https://mastheadata.com/bigquery/cost-queries/time-travel-storage-cost.md)
*   [Logical vs physical storage billing: which datasets to switchThis query computes each dataset's monthly storage cost under logical and physical billing with Google's own forecast formula, and the saving from switching.](https://mastheadata.com/bigquery/cost-queries/logical-vs-physical-storage.md)

## Waste

Unused tables, dead-end tables, failed jobs and repeated queries: spend that buys nothing.

*   [Failed BigQuery jobs and the slots they wasteThis query groups the last 30 days of failed BigQuery jobs by error reason, with how many failed, who ran them and the slot-hours they used before failing.](https://mastheadata.com/bigquery/cost-queries/failed-jobs-cost.md)
*   [Find dead-end tables: written but never readThis query finds tables that jobs wrote to in the last 30 days but no query read, and what building them cost.](https://mastheadata.com/bigquery/cost-queries/dead-end-tables.md)
*   [Find repeated BigQuery queries and cache missesThis query finds queries that run over and over with the same shape, with how often they ran, how often the result cache answered them and what they cost.](https://mastheadata.com/bigquery/cost-queries/repeated-queries.md)
*   [Find SELECT \ queries that scan whole tablesThis query finds the most expensive queries that start with SELECT FROM in the last 30 days, grouped by principal.](https://mastheadata.com/bigquery/cost-queries/select-star-queries.md)
*   [Find unused BigQuery tablesThis query finds tables older than 90 days that no query job has read in the last 90 days, with their size and monthly storage cost.](https://mastheadata.com/bigquery/cost-queries/unused-tables.md)
---

## Other pages in BigQuery Reference

> For the full index of this section, see [BigQuery Reference](https://mastheadata.com/llms/llms-bigquery-reference.txt).

- [BigQuery Aggregate Functions: COUNT, SUM, STRING_AGG and More | Masthead](https://mastheadata.com/bigquery/aggregate-functions.md): Aggregate functions collapse many rows into one value per group. 16 aggregate functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Array Functions: UNNEST, ARRAY_AGG and More | Masthead](https://mastheadata.com/bigquery/array-functions.md): ARRAY is a first-class type in BigQuery: nested and repeated fields are how BigQuery avoids joins. 11 array functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conditional Expressions: CASE, IF, COALESCE, IFNULL | Masthead](https://mastheadata.com/bigquery/conditional-expressions.md): Conditional expressions choose a value based on a condition or on NULLs. 5 conditional expressions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conversion Functions: CAST and SAFE_CAST | Masthead](https://mastheadata.com/bigquery/conversion-functions.md): Conversion functions change a value from one type to another. 3 conversion functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Date Functions: Syntax, Examples and Gotchas | Masthead](https://mastheadata.com/bigquery/date-functions.md): DATE functions in BigQuery (GoogleSQL) build, shift, truncate, compare and format calendar dates. 14 date functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Datetime Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/datetime-functions.md): DATETIME is a civil date and time with no time zone: what a wall clock shows. 8 datetime functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DDL: CREATE TABLE, Partitioning, Clustering and Views | Masthead](https://mastheadata.com/bigquery/ddl.md): Data definition language creates and changes tables, views, materialized views and functions. 8 DDL statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DML: INSERT, UPDATE, DELETE and MERGE | Masthead](https://mastheadata.com/bigquery/dml.md): Data manipulation language changes table rows. 5 DML statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Error Messages: Causes and Fixes | Masthead](https://mastheadata.com/bigquery/errors.md): 51 BigQuery error messages explained: what each one means, why it happens and how to fix it, from "Resources exceeded" and quota errors to permissions, DML conflicts and failed loads.
- [BigQuery Functions List: Syntax and Examples for Every Function | Masthead](https://mastheadata.com/bigquery/functions.md): All 143 BigQuery SQL functions we cover, by category: date, timestamp, string, array, JSON, aggregate, window and more. Each with syntax, runnable examples, common mistakes and cost notes.
- [GA4 BigQuery Export: SQL Queries for Sessions, Users, Events and Revenue | Masthead](https://mastheadata.com/bigquery/ga4.md): 28 SQL recipes for the GA4 BigQuery export: unnest event_params, sessions, users, traffic sources, engagement, ecommerce, retention, and how to keep the queries cheap. Every one runs on Google's public GA4 sample.
- [BigQuery INFORMATION_SCHEMA: Jobs, Tables, Storage and Costs | Masthead](https://mastheadata.com/bigquery/information-schema-views.md): INFORMATION_SCHEMA views expose BigQuery metadata as tables you can query: jobs, slots, bytes billed, tables, columns and storage. 2 INFORMATION_SCHEMA with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery JSON Functions: JSON_VALUE, JSON_QUERY and More | Masthead](https://mastheadata.com/bigquery/json-functions.md): BigQuery reads JSON stored as STRING or as the native JSON type. 14 JSON functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Math Functions: ROUND, SAFE_DIVIDE, MOD and More | Masthead](https://mastheadata.com/bigquery/math-functions.md): Mathematical functions round, divide, bucket and transform numbers. 15 mathematical functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Pricing Calculator: On-Demand vs Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing-calculator.md): Free BigQuery pricing calculator: compare on-demand ($6.25 per TiB) with Standard, Enterprise and Enterprise Plus editions per slot-hour, and logical vs physical storage billing, using your own numbers from INFORMATION_SCHEMA.
- [BigQuery Pricing Explained (2026): On-Demand, Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing.md): BigQuery bills compute and storage separately. Compute is on-demand at $6.25 per TiB scanned (the first 1 TiB a month is free) or capacity-based with editions from $0.04 per slot-hour. Storage costs $0.02 per GiB a month for active data and $0.01 for data unchanged for 90 days (US, logical).
- [BigQuery Public Datasets: Sizes, Tables and What They Cost to Query | Masthead](https://mastheadata.com/bigquery/public-datasets.md): 40 BigQuery public datasets with their real table sizes and what querying them costs: GitHub, Stack Overflow, Wikipedia, Google Trends, GA4 sample, NOAA weather, taxi trips, crypto and more, with cheap example queries.
- [BigQuery Query Syntax: QUALIFY, PIVOT, CTEs, JOINs and More | Masthead](https://mastheadata.com/bigquery/query-syntax.md): The clauses that shape a GoogleSQL query in BigQuery: CTEs, joins, set operations, PIVOT, QUALIFY and SELECT * EXCEPT. 11 query syntax with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Scripting: Variables, Loops, Dynamic SQL, LOAD and EXPORT | Masthead](https://mastheadata.com/bigquery/scripting.md): Multi-statement queries let you declare variables, loop, branch and build SQL at run time, and LOAD DATA and EXPORT DATA move data in and out of BigQuery from SQL.. 5 scripting and data movement with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery SQL Syntax: Statements, Clauses, DDL and DML | Masthead](https://mastheadata.com/bigquery/sql.md): BigQuery SQL syntax reference: QUALIFY, PIVOT, MERGE, CTEs, partitioned and clustered tables, scripting and INFORMATION_SCHEMA. 31 statements and clauses with examples and cost notes.
- [BigQuery String Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/string-functions.md): String functions in BigQuery split, search, replace, pad and format STRING values, and most also accept BYTES. 28 string functions with syntax, runnable examples, common mistakes and cost notes.
- [The Bill Is Right: Guess Your BigQuery Bill | Masthead](https://mastheadata.com/bigquery/the-bill-is-right.md): A free game show for data teams. Guess the monthly BigQuery bill from real Google Cloud list prices: three tries, land within 15% to win.
- [BigQuery Timestamp Functions: Syntax, Time Zones and Examples | Masthead](https://mastheadata.com/bigquery/timestamp-functions.md): TIMESTAMP is an absolute point in time with microsecond precision, stored in UTC. 12 timestamp functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Hash and Utility Functions: FARM_FINGERPRINT, UUID, SHA256 | Masthead](https://mastheadata.com/bigquery/utility-functions.md): Hashing, unique IDs and a few utility functions that show up in pipelines: deterministic sampling, surrogate keys, deduplication and raising your own errors.. 6 hash and utility functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Window Functions: ROW_NUMBER, LAG, RANK and More | Masthead](https://mastheadata.com/bigquery/window-functions.md): Window (analytic) functions compute a value for every row from a window of related rows, defined with OVER (PARTITION BY ... 11 window functions with syntax, runnable examples, common mistakes and cost notes.
