Skip to content

Instantly share code, notes, and snippets.

@vinayakg
Created August 4, 2024 14:34
Show Gist options
  • Save vinayakg/3cf1f9a9365136cec0c2e1c680a1edab to your computer and use it in GitHub Desktop.
Save vinayakg/3cf1f9a9365136cec0c2e1c680a1edab to your computer and use it in GitHub Desktop.
GCP Bill Export Query
-- Get GCP billing from billing export
SELECT
invoice.month AS billing_month,
service.description AS service_name,
sku.description AS sku_description,
usage.amount AS usage_amount,
usage.unit AS usage_unit,
USAGE.amount_in_pricing_units AS amount_in_pricing_units,
USAGE.pricing_unit AS pricing_unit,
price.effective_price AS unit_price,
cost AS total_cost,
project.id AS project_id
FROM
up_billing.gcp_billing_export_resource_v1_0152BE_CFA1F8_83B5B5 b-- Replace with your actual table name
WHERE
-- You can add WHERE clauses here to filter specific dates, services, etc.
invoice.month = '202407'
-- DATE(usage_start_time) BETWEEN '2024-06-01' AND '2024-06-30'
-- DATE(usage_start_time) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 24 DAY) AND CURRENT_date()
-- AND service.description = 'Compute Engine'
ORDER BY
billing_month DESC,
total_cost DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment