BigQuery cost query · Cost attribution
BigQuery cost of Looker Studio dashboards
This 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. Dashboards that refresh often on large tables are one of the most common hidden BigQuery costs.
The query
SELECT
(SELECT value FROM UNNEST(labels) WHERE key = 'looker_studio_datasource_id') AS datasource_id,
COUNT(*) AS queries,
ROUND(COUNTIF(cache_hit) / COUNT(*) * 100, 1) AS cache_hit_pct,
ROUND(SUM(total_bytes_billed) / POW(1024, 4) * 6.25, 2) AS est_on_demand_usd,
ANY_VALUE(LEFT(query, 200)) AS example_query
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
AND job_type = 'QUERY'
AND EXISTS (SELECT 1 FROM UNNEST(labels) WHERE key = 'looker_studio_datasource_id')
GROUP BY datasource_id
ORDER BY est_on_demand_usd DESC;How it works
Looker Studio labels the BigQuery jobs it runs with the ID of the data source that issued them (looker_studio_datasource_id). Grouping by it shows what each data source costs, however many reports use it. The data source ID is in the URL of the data source in Looker Studio.
A low cache_hit_pct with a high cost usually means the data source queries a large table directly with filters that change per viewer. Pointing it at a pre-aggregated table, or a partitioned one with a date filter in the report, cuts the cost per view.
Output columns
| Column | Meaning |
|---|---|
datasource_id | Looker Studio data source that issued the jobs. |
cache_hit_pct | Share of the jobs answered from BigQuery's result cache, which are free. |
est_on_demand_usd | On-demand list price of the bytes billed. |
Permissions and notes
Needs: bigquery.jobs.listAll on the project, for example through the BigQuery Resource Viewer role (roles/bigquery.resourceViewer). To see only your own jobs, query JOBS_BY_USER instead.
- The
6.25is the on-demand list price per TiB in the US and EU multi-regions. If your projects run on editions, cost follows slot-hours instead: multiplyslot_hoursby your edition's price per slot-hour (see BigQuery pricing). - Looker Studio may set other labels on its jobs too; look at
labelson one of them to see what your version adds. - Jobs run with viewer credentials are billed to the viewer's billing project, so look in that project's JOBS view.
FAQ
How do I make a Looker Studio dashboard cheaper on BigQuery?
Query a small aggregated table instead of raw events, partition the source by date and keep a date range control on the report, and avoid custom queries that rebuild large joins on every view. BI Engine can also serve repeated dashboard queries from memory.
Are cached Looker Studio queries free?
Queries answered from BigQuery's result cache are not billed. Looker Studio also has its own cache, which doesn't create BigQuery jobs at all.
Related
All BigQuery cost queries · Data FinOps playbook · Pricing calculator
