Skip to content

Instantly share code, notes, and snippets.

@sleroy
Created June 15, 2025 09:27
Show Gist options
  • Save sleroy/14536d232e2483db1e53caf694429842 to your computer and use it in GitHub Desktop.
Save sleroy/14536d232e2483db1e53caf694429842 to your computer and use it in GitHub Desktop.
Extract billing from BigQuery
SELECT
project.id as ID,
invoice.month as Month,
service.description as ServiceDescription,
service.id as ServiceID,
sku.description as SKUDescription,
sku.id as SKUID,
location.location as Region,
SUM(usage.amount_in_pricing_units) as UsageAmount,
usage.pricing_unit as UsageUnit,
SUM(cost) as ActualCost, #optional
FROM `<project>.<dataset>.gcp_billing_export_v1_<UUID>` # Replace project, table, and UUID.
WHERE invoice.month = "202304" # Modify this clause for the period of time.
AND cost_type = "regular" # This will filter out private pricing, credits, and discounts.
GROUP BY ID,
Month,
ServiceDescription,
ServiceID,
SKUDescription,
SKUID,
Region,
UsageUnit
ORDER BY ServiceID ASC, SKUID ASC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment