bigquery-utils icon indicating copy to clipboard operation
bigquery-utils copied to clipboard

Per user cost in BigQuery

Open upgradedcloud opened this issue 1 year ago • 1 comments

BigQuery per user cost ?

Hi all , is it possible to get the per user cost for bq in my project ?

upgradedcloud avatar Aug 18 '24 22:08 upgradedcloud

You could try getting a per-region and per-project estimate from the Information Schema https://cloud.google.com/bigquery/docs/information-schema-jobs

Here's a sample query for costs over the last 30 days:

SELECT
  user_email, 
  SUM(total_bytes_processed)/POWER(2,40) AS total_terabytes_processed, 
  SUM(total_bytes_processed)/POWER(2,40) * 5 AS estimated_cost -- Assuming $5 per TB
FROM 
  `<your-project>`.`region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT 
WHERE 
  creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY) 
  AND CURRENT_TIMESTAMP()
  AND job_type = 'QUERY' 
  AND state = 'DONE'
GROUP BY
  user_email
ORDER BY
 estimated_cost DESC; 

saurabh-net avatar Aug 20 '24 05:08 saurabh-net

Let us know if this works for you

afleisc avatar Sep 18 '24 15:09 afleisc