How to export Google Cloud billing data from BigQuery to CSV

BigQuery will not export your Cloud Billing table to CSV as it stands: labels and credits are repeated fields, and a local download of query results stops at 10 MB, per Google's BigQuery documentation (checked November 2026). Query first: flatten labels, sum credits into columns and group by invoice.month, then download that small, flat result.

The standard export table is gcp_billing_export_v1_<BILLING_ACCOUNT_ID>, and Google's own examples sum credits with UNNEST(credits) to get totals that match the invoice.

Why can’t I just download the billing table as CSV?

Google's BigQuery documentation is plain about it: "BigQuery doesn't support exporting nested or repeated data (RECORD / STRUCT or ARRAY data types) to CSV format." The Cloud Billing standard export schema adds: "Certain fields such as labels and credits are repeated." labels is an array of key/value pairs, and credits is an array of records, each with its own type and a negative amount. A CSV export of the raw table is refused.

The table structure is defined by Google’s schema, and it’s not optional. You cannot disable these fields. The only path to a usable CSV is to write a query that flattens them.

Do not fix this with a plain CROSS JOIN UNNEST(labels). That join drops every line item without labels and repeats each line item's cost once per label, so your totals stop matching the invoice. Turn labels into one string per line item and sum credits per line item instead, as in the query below.

How do I check if my billing export is set up?

In the Google Cloud console, open Billing, select your billing account, then open Billing export and the BigQuery export tab. Confirm that Standard usage cost is enabled, with a project and dataset. Detailed usage cost, Pricing and FOCUS are each enabled separately; the CSV in this article needs only Standard usage cost.

Put the export in a multi-region (US or EU) dataset. A multi-region dataset gets the current and previous month retroactively, and that initial backfill can take up to five days. A regional dataset gets nothing from before the export was enabled, so choose the location before you save the settings. After that, Cloud Billing exports data automatically throughout the day.

The table is PROJECT_ID.DATASET.gcp_billing_export_v1_<BILLING_ACCOUNT_ID>, in the project and dataset you chose when you enabled the export. List your billing account IDs and confirm the table exists:

gcloud billing accounts list
bq ls PROJECT_ID:DATASET

Check your own bill in 2 minutes: https://revelations.consulting/checker?utm_source=blog&utm_medium=organic&utm_content=blog-google-cloud-billing-bigquery-to-csv

How do I fix it and get a usable CSV?

Write a query that flattens labels into a single string, sums credits into columns, and groups by month, service, SKU, project, cost type, currency and labels. The credit sums follow Google's "Sum of all costs, per invoice" example:

WITH line_items AS (
  SELECT
    invoice.month AS invoice_month,
    service.description AS service_description,
    sku.id AS sku_id,
    sku.description AS sku_description,
    project.id AS project_id,
    cost_type,
    currency,
    IFNULL((SELECT STRING_AGG(CONCAT(l.key, '=', l.value), ';' ORDER BY l.key, l.value)
            FROM UNNEST(labels) AS l), '') AS labels,
    cost,
    credits
  FROM `PROJECT_ID.DATASET.gcp_billing_export_v1_<BILLING_ACCOUNT_ID>`
  WHERE invoice.month >= FORMAT_DATE('%Y%m', DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH))
    AND invoice.month < FORMAT_DATE('%Y%m', CURRENT_DATE())
)
SELECT
  invoice_month,
  service_description,
  sku_id,
  sku_description,
  project_id,
  cost_type,
  currency,
  labels,
  SUM(cost) AS cost_before_credits,
  SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS all_credits,
  SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS cost_after_credits,
  SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c WHERE c.type = 'PROMOTION'), 0)) AS promotion_credits,
  SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c WHERE c.type = 'COMMITTED_USAGE_DISCOUNT'), 0)) AS cud_credits,
  SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c WHERE c.type = 'COMMITTED_USAGE_DISCOUNT_DOLLAR_BASE'), 0)) AS cud_dollar_base_credits,
  SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c WHERE c.type = 'FEE_UTILIZATION_OFFSET'), 0)) AS fee_utilization_offset_credits
FROM line_items
GROUP BY
  invoice_month,
  service_description,
  sku_id,
  sku_description,
  project_id,
  cost_type,
  currency,
  labels
ORDER BY invoice_month DESC, cost_after_credits DESC

The subquery turns each line item's labels array into one key=value;key=value string, sorted so identical labels always give the same string. Credits are summed per line item, never joined, so every line item counts once and unlabeled line items stay in. The four type columns cover PROMOTION, COMMITTED_USAGE_DISCOUNT, COMMITTED_USAGE_DISCOUNT_DOLLAR_BASE and FEE_UTILIZATION_OFFSET. Other credit types exist, and all_credits includes every credit, so all_credits will not always equal the sum of those four columns.

Run the query in BigQuery. In the query results, click Save results and choose CSV (local file) if the result is under the 10 MB local download limit, or CSV (Google Drive) for results of 1 GB or less.

Keep cost_type as a column. Its values are regular, tax, adjustment and rounding error, and your invoice includes all four, so do not filter to regular when you reconcile. Add up cost_after_credits across every row for one invoice_month and compare it with that month's invoice; if they differ, check that every cost_type is in and that the currency matches.

Do not use the BigQuery sandbox for long-term storage. The BigQuery sandbox needs no credit card and gives you 10 GiB of storage and 1 TiB of queries a month, but its tables expire after 60 days. You cannot rely on the sandbox to hold your billing history.

What it usually looks like

The raw standard export has many rows per SKU per day, so an ungrouped month outgrows a local download fast. Grouping by invoice.month collapses those rows. If the grouped result is still too big, look at labels first: one label with a unique value per deployment or per pod splits every row it touches.

Patterns to check in your own CSV:

  • One or two projects carry most of the spend. Sort one invoice_month by cost_after_credits.
  • Credits are negative amounts. A non-zero promotion_credits column is promotional money; subtract promotion_credits from cost_after_credits to see what you pay once the promotion ends.
  • The same label written several ways (env=prod, Env=Prod, environment=production) splits one team's cost across rows.
  • Rows with an empty labels column are cost nobody has tagged.

You won’t see resource names like VM instance IDs or bucket names. The standard export doesn’t include them. If you need per-resource detail, you must use the Detailed usage cost export, which is larger and more complex.

If you want a second pair of eyes on the CSV, book a free 30-minute consult: we'll look at your bill with you, no obligation and no sales pitch. https://revelations.consulting/?utm_source=blog&utm_medium=organic&utm_content=blog-google-cloud-billing-bigquery-to-csv#contact

The /checker query reads the standard export for the last 3 full invoice months, flattens labels to key=value;key=value, sums credits into columns, and groups by month, service, SKU, project, cost type, currency and labels to stay under 10 MB in most accounts. The /checker query returns 19 columns, starting invoice_month, service_description, sku_id, sku_description, project_id, cost_type, currency.

The /checker counts cost after credits except PROMOTION, which it reports separately. The standard export has no resource names, so neither does the /checker output. The query is checked against Google's schema but not yet run on a real billing table.

Run your own numbers: Google Cloud bill checker

Frequently asked questions

How do I enable Cloud Billing export to BigQuery?

In the Google Cloud console, open Billing, select your billing account, open Billing export, and on the BigQuery export tab edit the settings for Standard usage cost, choosing a project and a multi-region (US or EU) dataset. Detailed usage cost, Pricing and FOCUS are enabled separately. A multi-region dataset gets the Cloud Billing export's current and previous month retroactively, and that initial backfill can take up to five days.

Why does my BigQuery query return 0 rows?

A Cloud Billing export query returns 0 rows when no data has landed yet or the query points at the wrong table. On a multi-region dataset the initial backfill can take up to five days, and a regional dataset holds nothing from before the export was enabled, so a filter on the last 3 full invoice months may find little or nothing at first. Confirm the exact table name with bq ls PROJECT_ID:DATASET and query it by its full path, PROJECT_ID.DATASET.gcp_billing_export_v1_<BILLING_ACCOUNT_ID>.

Can I use the BigQuery sandbox to store my billing data?

No. The BigQuery sandbox needs no credit card and gives you 10 GiB of storage and 1 TiB of queries a month, but its tables expire after 60 days. Use the BigQuery sandbox to test queries, not to hold a billing export long term.

How do I find which project is spending the most?

Group the Cloud Billing standard export by project.id for one invoice.month and sort by SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) descending. The top rows are the Google Cloud projects with the highest cost after credits that month.

What if my CSV is over 10 MB?

When BigQuery query results are over the 10 MB local CSV download limit, save them to Google Drive instead: in the query results, click Save results and choose CSV (Google Drive). Google Drive takes BigQuery results of 1 GB or less; above that, group the query further, for example by month and service only.

Run the numbers on your own bill: Cloud Bill Gotchas Checker. Free, in your browser.

Want this kind of thing weekly? Get Cloud Bill Weekly. Want us to find it in your bill? We're taking three founding clients for a free Cost Assessment.