πŸ§ͺ How to Run Sample Billing Queries in BigQuery

Once your billing data is exported to BigQuery, you can write SQL queries to analyze cloud spending by project, SKU, time range, and more. Here’s how to run a sample cost breakdown query over the last 30 days.

πŸ“‹ Step-by-Step Instructions

  • Open the BigQuery Console.
  • Select your billing dataset from the left-hand panel.
  • Click Compose Query.
  • Paste the sample query below into the editor.
  • Click Run to execute the query.

πŸ’‘ Example Query

SELECT
  project.name,
  sku.description,
  cost
FROM
  `my_project.my_dataset.gcp_billing_export`
WHERE
  usage_start_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
ORDER BY
  cost DESC
LIMIT 10;

Tip: Replace my_project.my_dataset.gcp_billing_export with your actual project and dataset name.

βœ… Expected Outcome

You’ll see a list of the top 10 SKUs with the highest costs in your project over the past 30 days, sorted by cost in descending order.

πŸ› οΈ Troubleshooting Tips

  • Query fails? Double-check your dataset and table name formatting.
  • No results? Ensure there’s billing data within the past 30 days and that the export is working correctly.

🧭 Related Articles or Next Steps

πŸ•“ Last Updated: April 2025