Export Cloud Billing data to BigQuery

Cloud Billing export to BigQuery lets you export detailed Google Cloud billing data (such as usage, cost estimates, and pricing data) automatically throughout the day to a BigQuery dataset. Then you can access your Cloud Billing data from BigQuery for detailed analysis. You can also use this export method to export data to a JSON file.

Timing is important. To access a more comprehensive set of Google Cloud billing data for your analysis needs, we recommend that you enable Cloud Billing data export to BigQuery at the same time that you create a Cloud Billing account.

See the limitations that might impact exporting your billing data to BigQuery.

Next steps

Managing and reporting costs effectively is a critical part of financial stewardship, whether you're running a multi-billion-dollar enterprise business or small household budget. Making data-driven decisions about your Google Cloud costs and usage starts with collecting the data you'll need to inform those decisions.

Refer to the guides in this section to learn about the following tasks:

Set up Cloud Billing data export to BigQuery

To start collecting your Cloud Billing data, you must enable Cloud Billing data export to BigQuery for each type of billing export you need.

These are the types of Cloud Billing data that you can enable for export:

Export type Description
FOCUS usage cost (Preview)

The FOCUS usage cost export is an immutable BigQuery dataset that contains your detailed usage cost data normalized using the FinOps Open Cost and Usage Specification (FOCUS) standards. FOCUS is an open specification that defines clear requirements for technology billing data generators to produce consistent cost and usage datasets. The columns in the FOCUS export generally map to the fields in the Detailed usage cost export.

Learn how to enable the FOCUS usage cost billing export.

Standard usage cost

The Standard usage cost data export contains standard Cloud Billing account cost usage information, such as account ID, invoice date, services, SKUs, projects, labels, locations, cost, usage, credits, adjustments, and currency.

Use the Standard usage cost export to analyze broad trends in your cost data.

Learn how to enable the Standard usage cost billing export.

Detailed usage cost

The Detailed usage cost data export contains detailed Cloud Billing account cost usage information. The detailed export schema includes everything in the standard usage cost data plus resource-level cost data, like a virtual machine or SSD that generates service usage.

Use the Detailed usage cost export to analyze costs at the resource level, and identify specific resources that might be driving up costs.

The detailed export includes granular cost information about several services. To view information about GKE, you must also enable cost allocation in detailed exports. Review the schema of the detailed usage cost data for further recommendations and limitations.

Learn how to enable the Detailed usage cost billing export.

Pricing data

The Pricing data export contains Cloud Billing account pricing information, such as billing account ID, services, SKUs, products, geographic metadata, pricing units, currency, aggregation, and tiers.

Learn how to enable the Pricing export.

You can also get your Cloud Billing account pricing data in these ways:

Committed Use Discounts Export (Preview) For customers who purchase CUDs, the Committed use discounts (CUD) metadata export provides a daily export of CUD metadata to a BigQuery table, which you can join with other billing data exports for better CUD management and reporting. CUD metadata includes information such as billing account ID, product ID, consumption model ID, commitment amount units and values, and more.
(Resellers only) Rebilling data export

For Resellers only, the Rebilling data export contains detailed Cloud Billing account cost usage information across all of your Reseller Billing Accounts annotated with Partner specific attributes.

Use the Rebilling data export to manage billing operations for your Google Cloud customers. Learn more about Repricing configurations which let you generate end-customer costs.

You incur BigQuery usage charges when you use BigQuery to store and analyze your billing usage and cost data. For more information, see BigQuery usage costs.

See the limitations that might impact exporting your billing data to BigQuery.

Understand the Cloud Billing data tables

After you enable Cloud Billing export to BigQuery, Cloud Billing data tables are automatically created in the BigQuery dataset.

To understand the data schema of your exported content, see the reference information for the contents of the Cloud Billing data that's exported to each table in the BigQuery dataset.

Find example queries for Cloud Billing data

Example queries are available for different types of exported billing data.

FOCUS usage cost

For FOCUS billing data, refer to the sample FOCUS queries that are available on the FinOps foundation site.

Standard usage cost, Detailed usage cost, and Pricing exports

For tips and guidance for using SQL to run queries on your Cloud Billing data for the Standard usage cost, Detailed usage cost, and Pricing exports, view the example queries.

On the example queries page, you'll find various SQL examples, including the following:

BigQuery usage costs

You incur BigQuery usage charges when you use BigQuery to store and analyze your billing usage and cost data. The primary costs in BigQuery are storage, for data that is stored in BigQuery, and compute, used for query processing.

Your BigQuery costs depend on how much data you store and how much data you query. Generally, storage costs are lower than query costs.

For more information about BigQuery costs, see Estimate and control costs in BigQuery.

Storage costs

Storage costs include the cost to store data that you load into BigQuery, and depends on your storage billing model.

  • Loading data into the designated dataset is free; this action takes advantage of BigQuery's pool of shared resources to load data in batches.
  • Many partitioned table operations are free, including loading data into partitions, copying partitions, and exporting data from partitions. Though free, these operations are subject to BigQuery's quotas and limits.
  • The FOCUS export is provided as an immutable export, using a linked dataset that Google pays for. You don't have storage costs for the most recent two years of FOCUS usage cost data, unless you copy and store the FOCUS data in a long-term storage table that you own.

For more information about best practices for optimizing the cost of BigQuery storage, see Control storage costs. You can also optimize storage for query performance.

Query costs

When you analyze your data, you are billed for all of the data that is read each time the query is run. Running queries has the potential to cause a cost spike.

For more information about best practices for optimizing costs when running queries in BigQuery, see Optimize query computation.

For detailed prices, review BigQuery pricing.

Limitations

Exporting Cloud Billing data to BigQuery is subject to the following limitations.

Table schema for the Cloud Billing data exports

The table schema for any of the Cloud Billing data exports can change.

When the table schema changes, such as when new fields are added to a BigQuery table schema for a Cloud Billing data export, any queries that directly reference the exported columns might fail. To resolve this, we recommend creating BigQuery views that query the exported tables and present the information in your preferred structure.

You can then adjust the queries that feed your reports and dashboards to pull from the views, instead of the exported tables. By using views, you can standardize the structure of the data used in your queries and dashboards.

The views you create should normalize the data so that all of the relevant tables present the same schema to your queries. This protects you from future schema changes, allowing you to modify the view's underlying query in those instances when the data schema changes.

FOCUS export and data retention

Billing data exported to the Google-provided FOCUS BigQuery export is subject to a 2-year Time To Live (TTL) policy. Data older than two years is automatically deleted from the provided FOCUS export table in the BigQuery dataset. If you need to retain your FOCUS billing data history beyond two years, copy the FOCUS data to a long-term storage table that you own.

BigQuery dataset locations and data availability

BigQuery dataset locations supported for use with Cloud Billing data:

BigQuery datasets are configured to use a location; either a multi-region location (EU or US), or a region location. The dataset location is set at creation time. After a dataset is created, its location can't be changed.

Cloud Billing data export supports all multi-region locations (EU or US), but only a subset of region locations. When you're configuring your Cloud Billing export settings, if you create or select a dataset that's configured to use an unsupported region location, when you attempt to save your export settings, you'll see an Invalid dataset region error.

The following table lists the multi-region locations and the region locations that are supported for use with BigQuery datasets that contain Cloud Billing data.

Americas Asia Pacific Europe Middle East

Multi-region: US

Regions:

  • northamerica-northeast1 (Montréal)
  • southamerica-east1 (São Paulo)
  • us-central1 (Iowa)
  • us-east1 (South Carolina)
  • us-east4 (Northern Virginia)
  • us-west1 (Oregon)
  • us-west2 (Los Angeles)
  • us-west3 (Salt Lake City)
  • us-west4 (Las Vegas)

Regions:

  • asia-east1 (Taiwan)
  • asia-east2 (Hong Kong)
  • asia-northeast1 (Tokyo)
  • asia-northeast2 (Osaka)
  • asia-northeast3 (Seoul)
  • asia-south1 (Mumbai)
  • asia-southeast1 (Singapore)
  • asia-southeast2 (Jakarta)
  • australia-southeast1 (Sydney)

Multi-region: EU

Regions:

  • europe-central2 (Warsaw)
  • europe-north1 (Finland)
  • europe-west1 (Belgium)
  • europe-west2 (London)
  • europe-west3 (Frankfurt)
  • europe-west4 (Netherlands)
  • europe-west6 (Zurich)

Regions:

  • me-central1 (Doha)
  • me-central2 (Dammam)
  • me-west1 (Tel Aviv)

Locations and data availability:

  • For your BigQuery datasets containing FOCUS usage cost data, standard usage cost data, or detailed usage cost data, the type of location you configure on the dataset impacts the timing of when your Google Cloud billing data is exported to the dataset:

    • If you configure the dataset to use a multi-region location (EU or US), the dataset includes Google Cloud billing data incurred from the start of the previous month from when you first enabled the export, unless you are re-enabling the export. That is, Google Cloud billing data is added retroactively for the current and previous month. For the initial backfill of exported data, it might take up to five days for your retroactive Cloud Billing data to finish exporting before you start seeing your current usage data.
    • If your dataset is configured to use a supported region location, your FOCUS usage cost data, standard usage cost data, and detailed usage cost data only reflect Google Cloud billing data incurred starting from the date you enabled Cloud Billing export, and after. That is, Google Cloud billing data is not added retroactively for non-multi-region dataset locations, so you won't see Cloud Billing data from before you enable export.

    • For more details, see Data availability.

  • Your BigQuery datasets containing pricing data only collect Google Cloud billing data incurred from the date you set up Cloud Billing export, and after. That is, Google Cloud pricing data isn't added retroactively, so you won't see Cloud Billing pricing data from before you enable export. For more details, see Data availability.

Disable, re-enable, or edit export settings

If you disable, re-enable, or edit your export settings to update the project or dataset where your exported billing data is stored, previously exported billing data isn't backfilled to your new dataset. To include the billing information that was exported prior to switching to a different project or dataset, you must manually join the new dataset with the previous dataset. For more information, see Join operation.

Dataset encryption

BigQuery datasets are configured to use encryption at rest by setting an encryption key option when you create the dataset – either a Google-owned and Google-managed encryption key, or a customer-managed encryption key (CMEK). The dataset encryption option can only be set at creation time. After a dataset is created, its encryption setting can't be changed.

If you already enabled the Cloud Billing data export to BigQuery, and your dataset is configured to use a Google-managed encryption key, you can use the bq command-line tool to enable CMEK on each table in the dataset. BigQuery will automatically use the dataset default key to protect the export tables, unless you configure it otherwise.

Learn about enabling CMEK for BigQuery tables.

Row level security

If you want to use BigQuery row-level security on the table that contains your exported data, you must give the Cloud Billing export service account billing-export-bigquery@system.gserviceaccount.com full access to the table using the BigQuery TRUE filter. The following command grants access to the Cloud Billing service account:

CREATE ROW ACCESS POLICY cloud_billing_export_policy
ON `__project_id__.__dataset_id__.__table_id__`
GRANT TO ('serviceAccount:billing-export-bigquery@system.gserviceaccount.com')
FILTER USING (TRUE);

FOCUS or detailed usage cost data and GKE

When exporting FOCUS usage cost data or detailed usage cost data, the export automatically includes resource-level information about Compute Engine and other services. However, for Google Kubernetes Engine (GKE) data, to view a breakdown of GKE cluster costs in a FOCUS or detailed data export, you must also enable cost allocation for GKE.

Resource-level tags

Resource-level Tags might take up to an hour to propagate to BigQuery exports. If a tag was added or removed within an hour, or if a resource has existed for less than an hour, it might not appear in the export.

Resource-level tags are available for several resources in the standard usage cost export and the detailed usage cost export.