Skip to content

Instantly share code, notes, and snippets.

@vinoaj
Created March 7, 2019 23:21
Show Gist options
  • Save vinoaj/173f9173e9b05f59723b9d1dd4c34014 to your computer and use it in GitHub Desktop.
Save vinoaj/173f9173e9b05f59723b9d1dd4c34014 to your computer and use it in GitHub Desktop.
BigQuery SQL for GCP Billing Reports: Getting Total Costs by Project for the last 4 weeks
#standardSQL
SELECT
project.id AS project_id
, project.name AS project_name
, currency
, ROUND(SUM(cost),2) AS total_cost
FROM `<project_id>.<dataset_id>.gcp_billing_export_v1_XXXXXX_XXXXXX_XXXXXX`
WHERE _PARTITIONTIME BETWEEN TIMESTAMP(DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)) AND TIMESTAMP(CURRENT_DATE())
AND project.id IS NOT NULL
GROUP BY project_id, project_name, currency
ORDER BY total_cost DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment