This chapter covers the configuration, mechanism, and best practices for exporting Google Cloud billing data into BigQuery for detailed cost analysis. For the ACE exam, understanding how to enable and query billing exports is critical because it directly supports cost management, budget tracking, and resource optimization — topics that appear in roughly 5-10% of exam questions. You will learn the step-by-step setup, the schema of exported tables, and common analytical queries that demonstrate your ability to monitor and control cloud spending.
Jump to a section
Imagine you run a large company with hundreds of employees, each using company credit cards for various expenses. You need to understand spending patterns to optimize costs. Instead of manually collecting receipts, you set up an automated system where every credit card transaction is instantly copied into a shared spreadsheet that your finance team can query with complex formulas. This is exactly what Billing Data Export to BigQuery does for your Google Cloud usage. Every hour, Google Cloud's billing system generates detailed usage and cost records, similar to individual transaction receipts. These records are automatically exported into BigQuery tables, which act like a powerful spreadsheet that can handle petabytes of data. You can then run SQL queries to analyze spending by project, service, label, or any dimension. The export is not real-time but near-real-time, with data typically available within 5-6 hours of usage. This is analogous to your credit card company posting transactions daily, not instantly. The BigQuery export includes both standard usage cost data and detailed pricing data, allowing you to build custom cost allocation reports, track budget utilization, and even predict future spend. Without this export, you would be limited to the pre-built reports in the Cloud Console, which lack the flexibility to join usage data with your own business dimensions like cost center or environment type.
What is Billing Data Export to BigQuery?
Billing Data Export to BigQuery is a Google Cloud feature that automatically copies your Cloud Billing usage and cost data into BigQuery datasets. This enables you to run custom SQL queries, join billing data with other datasets, and build sophisticated cost management dashboards. The export includes two main types of data: standard usage cost data (detailed cost and usage per SKU per project) and pricing data (the list prices for each SKU). Both are exported to separate tables within a BigQuery dataset that you designate.
Why It Exists
Google Cloud provides built-in cost reports in the Cloud Console (e.g., Cost Table, Reports, Budgets). However, these are limited in flexibility. For enterprise-scale cost management, you need to:
Join usage data with your own business dimensions (e.g., cost center, environment)
Create custom allocation rules (e.g., shared costs)
Build real-time or near-real-time dashboards
Perform historical trend analysis over years
Export data to external tools via BigQuery's export capabilities
Billing Export to BigQuery solves these needs by giving you raw, granular data in a fully queryable format.
How It Works Internally
The export process is fully managed by Google. Once enabled, the following happens:
1. Activation: You enable the export in the Cloud Console under Billing > Cost Management > Data Export. You select a BigQuery dataset (which must be in the same multi-region or region as your billing account).
2. Data Generation: Every hour, Google Cloud's billing pipeline aggregates usage and cost data from all projects under the billing account. This data is not real-time; there is a latency of 5-6 hours typically.
3. Table Population: The export writes to two primary tables:
- gcp_billing_export_v1_<billing_account_id>: Contains detailed cost and usage data.
- gcp_billing_export_resource_v1_<billing_account_id>: Contains resource-level cost data (more granular, includes resource labels).
- cloud_pricing_export: Contains SKU-level pricing data (optional, must be enabled separately).
4. Schema: The tables have a fixed schema with columns like:
- billing_account_id
- service.id and service.description
- sku.id and sku.description
- usage_start_time and usage_end_time (TIMESTAMP type)
- project.id and project.name
- labels (REPEATED RECORD of key-value pairs)
- cost (FLOAT, the cost in USD)
- currency
- usage.amount and usage.unit
- credits (REPEATED RECORD for any credits applied)
- invoice_month (STRING in YYYYMM format)
5. Data Freshness: The export runs daily, but data for each hour is typically available within 5-6 hours. For example, usage from 10:00-11:00 AM might appear in BigQuery by 4:00-5:00 PM the same day.
Key Components, Values, and Defaults
Billing Account: Must be a Cloud Billing account (self-serve or invoiced).
BigQuery Dataset: Must exist in the same multi-region (e.g., US, EU) as the billing account location. The dataset can be in any project, but the billing account must have permission to write to it.
Table Names: Auto-generated based on a template. You cannot rename them.
Data Retention: BigQuery tables are append-only; data is never deleted unless you set an expiration on the dataset or table. Default: no expiration.
Cost: There is no additional charge for the export itself, but you pay for BigQuery storage and query costs.
Export Frequency: Hourly data is batched and written daily. There is no streaming option.
Pricing Export: Enabled separately. It contains SKU prices that are updated monthly.
Configuration and Verification
To enable the export: 1. Navigate to Cloud Console > Billing > select your billing account. 2. Click on "Cost Management" > "Data Export". 3. Under "Detailed usage cost", click "Edit" and select a BigQuery dataset. 4. (Optional) Enable "Pricing export" by clicking "Edit" and selecting the same dataset. 5. Click "Save".
To verify:
After saving, the export tables are created within 24 hours.
Run a simple query in BigQuery:
SELECT * FROM `project.dataset.gcp_billing_export_v1_<billing_account_id>`
WHERE DATE(usage_start_time) = CURRENT_DATE()
LIMIT 10;If you get results, the export is working.
You can also check the billing account's export status in the Cloud Console under the same Data Export page.
Interaction with Related Technologies
Budgets and Alerts: Budget thresholds can trigger Pub/Sub notifications, which can then be used to automate cost controls (e.g., disable non-critical resources). The budget data is separate from the export, but you can join them in BigQuery if you export budget alerts to BigQuery as well.
Cloud Monitoring: You can create custom dashboards in Monitoring using BigQuery as a data source via the Monitoring Query Language (MQL).
Cloud Asset Inventory: Exports asset metadata that can be joined with billing data to analyze cost per resource type.
Cloud Scheduler: Can be used to run periodic queries that generate cost reports and email them.
Looker Studio: Connect BigQuery to Looker Studio (formerly Data Studio) to build interactive dashboards.
Common Query Patterns
ACE candidates should be able to write queries that answer typical cost management questions:
Total cost per project:
SELECT project.id, SUM(cost) AS total_cost
FROM `project.dataset.gcp_billing_export_v1_*`
WHERE DATE(usage_start_time) >= '2025-01-01'
GROUP BY project.id
ORDER BY total_cost DESC;Cost by service:
SELECT service.description, SUM(cost) AS total_cost
FROM `project.dataset.gcp_billing_export_v1_*`
GROUP BY service.description
ORDER BY total_cost DESC;Cost by label:
SELECT labels.key, labels.value, SUM(cost) AS total_cost
FROM `project.dataset.gcp_billing_export_v1_*`, UNNEST(labels) AS labels
GROUP BY labels.key, labels.value
ORDER BY total_cost DESC;Monthly cost trend:
SELECT invoice_month, SUM(cost) AS total_cost
FROM `project.dataset.gcp_billing_export_v1_*`
GROUP BY invoice_month
ORDER BY invoice_month;Credits applied:
SELECT invoice_month, SUM(cost) AS total_cost, SUM(credits.amount) AS total_credits
FROM `project.dataset.gcp_billing_export_v1_*`, UNNEST(credits) AS credits
GROUP BY invoice_month;Note: The wildcard * in the table name is useful if you have multiple billing accounts or if you want to query all historical tables. However, the standard table name does not include a date suffix; it is a single table that grows over time. The wildcard * works because BigQuery treats the table as a wildcard match if you use a common prefix, but in practice, for a single billing account, you can just use the exact table name.
Performance Considerations
Querying large billing tables can be expensive if you use SELECT * without filtering. Always filter by usage_start_time or invoice_month to limit the data scanned.
Partitioning: The tables are not partitioned by default. You can create a view or a partitioned copy of the table to improve query performance and reduce cost.
Clustering: You can cluster the table by project.id or service.id to optimize queries that filter on those columns.
Materialized views: For common aggregations, consider creating materialized views to avoid scanning the entire table each time.
Enable Billing Export in Console
Navigate to Cloud Console > Billing > select your billing account. Under 'Cost Management', click 'Data Export'. Click 'Edit' next to 'Detailed usage cost'. Choose an existing BigQuery dataset or create a new one. The dataset must be in the same multi-region as your billing account (US or EU). Click 'Save'. The export tables will be created within 24 hours. Optionally, enable 'Pricing export' by clicking 'Edit' and selecting the same dataset. This will create a separate table for SKU pricing.
Verify Table Creation and Schema
After 24 hours, go to BigQuery in the Cloud Console. Find the dataset you selected. You should see tables with names like 'gcp_billing_export_v1_<billing_account_id>' and 'gcp_billing_export_resource_v1_<billing_account_id>'. Click on the table to view its schema. Verify columns such as 'cost', 'usage_start_time', 'project.id', 'service.id', and 'labels'. If the pricing export was enabled, you will also see a table named 'cloud_pricing_export'.
Run a Sample Query
In the BigQuery query editor, run a simple query to confirm data is flowing: SELECT * FROM `project.dataset.gcp_billing_export_v1_<billing_account_id>` LIMIT 10. Replace project, dataset, and billing_account_id with your actual values. If you see rows with usage data, the export is working. Note that data may have a latency of up to 6 hours, so recent hours might be missing. Use DATE(usage_start_time) = CURRENT_DATE() to see today's data.
Set Up Budget Alerts with Pub/Sub
To automate cost management, create a budget in Cloud Console > Billing > Budgets & alerts. Set an amount and threshold percentages (e.g., 50%, 90%, 100%). Under 'Manage notifications', select 'Pub/Sub topic' and choose an existing topic or create a new one. This will send a message to the topic when the threshold is exceeded. You can then have a Cloud Function or other service consume the message and take action (e.g., disable resources or send Slack alerts).
Build a Cost Dashboard in Looker Studio
Connect Looker Studio (formerly Data Studio) to your BigQuery billing export table. Create a new report and add a 'BigQuery' data source. Select the billing table. Build visualizations such as a time series of daily costs, a pie chart of cost by service, and a table of top projects by cost. Use filters to allow users to select a date range or project. This provides a self-service cost analysis tool for your organization.
Enterprise Scenario 1: Multi-Project Cost Allocation
A large enterprise with 50+ projects across multiple GCP organizations needs to allocate costs to internal departments. They enable billing export to BigQuery and create a custom table mapping project IDs to cost centers (e.g., 'project-123' -> 'Engineering'). They run a weekly SQL query that joins the billing export with this mapping table to produce a cost report per cost center. The query filters on usage_start_time for the past week and groups by cost center. They also use labels on resources to further break down costs (e.g., environment='prod' vs 'dev'). One common misconfiguration is not labeling resources consistently, leading to inaccurate allocation. They set up a Cloud Scheduler job to run the query every Monday and email the results to finance.
Enterprise Scenario 2: Real-Time Budget Enforcement
A SaaS company wants to prevent cost overruns on their development projects. They set up a budget with a 80% threshold that triggers a Pub/Sub notification. A Cloud Function subscribes to the topic and, upon receiving the alert, queries BigQuery to get the current month's cost for the dev project. If it exceeds the budget, the function disables a specific set of non-critical resources (e.g., staging VMs) using the Cloud Resource Manager API. They also log the action to BigQuery for auditing. The challenge is the latency of billing export (5-6 hours), so the budget alert is not real-time. To mitigate, they use a combination of budget alerts and near-real-time Monitoring metrics (e.g., resource utilization) to trigger early warnings.
Scenario 3: Chargeback for Shared Services
A company runs shared infrastructure (e.g., a central Kubernetes cluster) used by multiple teams. They enable billing export and use resource labels to tag each pod's namespace. The billing export table includes labels in a repeated record. They run a daily query that sums cost per label key 'team' and produces a chargeback report. They discovered that some pods were not labeled, resulting in an 'unallocated' cost bucket. They implemented a policy to enforce labeling via a Kubernetes admission controller. They also use the pricing export table to calculate the cost of reserved instances vs. on-demand, and adjust chargeback rates accordingly.
What the ACE Exam Tests on This Topic
The ACE exam objective 4.2 focuses on 'Billing Data Export to BigQuery'. Specifically, you should know:
How to enable the export (Cloud Console, not gcloud command)
The schema of the exported tables (especially the columns cost, usage_start_time, project.id, labels, credits)
The latency of data (5-6 hours, not real-time)
That the export is free but BigQuery storage and query costs apply
How to query the data for common cost analysis (e.g., total cost per project, cost by service, cost by label)
The difference between standard usage cost export and resource-level export
That pricing export is optional and contains SKU prices
Common Wrong Answers and Why Candidates Choose Them
Wrong answer: 'Billing export data is available in real-time.' Candidates confuse the export with real-time Monitoring metrics. The reality is that there is a 5-6 hour latency.
Wrong answer: 'You can enable export using the gcloud command gcloud billing accounts export.' There is no such command; the export is only configurable via the Cloud Console.
Wrong answer: 'The export includes data for all projects under the billing account, including archived projects.' Actually, once a project is deleted or removed from the billing account, its billing data remains in the export table, but no new data is added.
Wrong answer: 'You can stream billing data to BigQuery in real-time using Pub/Sub.' This is not supported; the export is batch only.
Specific Numbers and Terms That Appear on the Exam
Latency: 5-6 hours (often asked as 'How long after usage does data appear in BigQuery?')
Table name pattern: gcp_billing_export_v1_<billing_account_id> and gcp_billing_export_resource_v1_<billing_account_id>
Pricing export table: cloud_pricing_export
Cost column: cost (type FLOAT)
Time columns: usage_start_time and usage_end_time (type TIMESTAMP)
Labels: stored as REPEATED RECORD with key and value
Export frequency: hourly data, written daily
Edge Cases and Exceptions
If you change the billing account linked to a project, the export for the new billing account will only contain data from the time of the change. Historical data remains in the old billing account's export.
If you disable the export and re-enable it, a new table is created with a different name (the billing account ID is the same, but the table is recreated). The old table is not deleted unless you manually delete it.
The export table is not partitioned by default. To improve query performance, you can create a partitioned copy or use clustering.
The labels column only contains labels that were applied at the time of usage. If you add labels later, historical usage data will not be retroactively labeled.
How to Eliminate Wrong Answers
Look for keywords like 'real-time' – if the answer claims real-time, it is wrong.
If the answer mentions a gcloud command for enabling export, it is likely wrong.
If the answer says the export includes data for all billing accounts, it is wrong; each billing account has its own export.
If the answer says you can export to Cloud Storage, that is a different feature (billing export to CSV/JSON to Cloud Storage), not BigQuery.
Billing export to BigQuery has a 5-6 hour latency; it is not real-time.
Enable export via Cloud Console under Billing > Cost Management > Data Export.
The main tables are gcp_billing_export_v1_<billing_account_id> and gcp_billing_export_resource_v1_<billing_account_id>.
Pricing export is optional and creates a cloud_pricing_export table.
Query cost by project, service, or label using SQL on the cost column.
Use WHERE clause on usage_start_time to limit data scanned and reduce costs.
Labels in billing data are stored as REPEATED RECORD; use UNNEST() to query them.
There is no charge for the export itself, but BigQuery storage and query fees apply.
These come up on the exam all the time. Here's how to tell them apart.
BigQuery Billing Export
Data exported to BigQuery tables for SQL querying.
Supports complex joins and aggregations.
Includes detailed usage cost and resource-level data.
Data is append-only; no file management needed.
Best for custom dashboards and automated analysis.
Cloud Storage Billing Export
Data exported as CSV or JSON files to Cloud Storage buckets.
Requires external processing to analyze (e.g., download and parse).
Includes only standard usage cost data (no resource-level).
Files are generated daily; must manage lifecycle.
Best for simple archival or import into on-prem systems.
Mistake
Billing data export to BigQuery is real-time.
Correct
Data is typically available within 5-6 hours of usage. It is not real-time; it is a daily batch update of hourly data.
Mistake
You can enable billing export using the gcloud command-line tool.
Correct
There is no gcloud command to enable BigQuery billing export. It must be done through the Cloud Console under Billing > Cost Management > Data Export.
Mistake
The export includes data for all projects across all billing accounts.
Correct
Each billing account has its own export tables. You must enable export separately for each billing account you want to analyze.
Mistake
Billing export tables are automatically partitioned by date.
Correct
The tables are not partitioned by default. You can create a partitioned copy or use clustering to optimize queries, but the original table is a single, unpartitioned table.
Mistake
You can export billing data to BigQuery without enabling it in the billing account.
Correct
You must have the appropriate permissions (Billing Account Administrator or Billing Account Viewer) and enable the export in the Cloud Console for that specific billing account.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Typically 5-6 hours. For example, usage from 10:00 AM will appear in BigQuery around 3:00-4:00 PM the same day. This is not real-time; it is a daily batch process. On the exam, remember the 5-6 hour latency.
No. There is no gcloud command for this. You must use the Cloud Console. Navigate to Billing > select your billing account > Cost Management > Data Export. This is a common exam trap.
Key columns include: billing_account_id, service.id, service.description, sku.id, sku.description, usage_start_time, usage_end_time, project.id, project.name, labels (REPEATED RECORD), cost, currency, usage.amount, usage.unit, credits (REPEATED RECORD), invoice_month. The cost column is of type FLOAT.
Use a WHERE clause on project.id: SELECT SUM(cost) FROM `project.dataset.gcp_billing_export_v1_*` WHERE project.id = 'my-project-id' AND DATE(usage_start_time) >= '2025-01-01'. Always filter on usage_start_time to limit data scanned.
No. The BigQuery export is batch with 5-6 hour latency. For near-real-time cost monitoring, you can use Cloud Monitoring metrics (e.g., estimated cost) or budget alerts with Pub/Sub, but these are estimates, not actual billing data.
Yes. Each billing account will create its own tables within the dataset. You can query across tables using a wildcard or union. However, table names include the billing account ID, so they are distinct.
Historical data for deleted projects remains in the export table. No new data is added after deletion. You can still query that data as long as the table exists.
You've just covered Billing Data Export to BigQuery — now see how well it sticks with free ACE practice questions. Full explanations included, no account needed.
Done with this chapter?