Skip to main content

GCP BigQuery Expression | Monthly Invoice Based on Labels

Updated 1 min readMarkdown
Part of seriesMLOps & Reliability
GCP BigQuery Expression | Monthly Invoice Based on Labels

In this GCP BigQuery expression, I show how you can retrieve the monthly invoice data on all resources in a specified project based on assigned label values. This method of capturing cloud spend can be applied after you've enabled the Cloud Billing data export to BigQuery functionality.

This query performs the following functions:

  • The sum of regular costs, taxes, adjustments and rounding errors for each invoice month using inner CAST

  • The CROSS JOIN statement excludes Null arrays/rows and UNNEST operator flattens the array of labels into rows

  • Filter by project name

  • Group by key/value labels and invoice month

  • Order by invoice month

This is just one scenario displaying the value of applying tags/labels on your cloud resources. I've found tagging essential when it comes to cloud cost analysis, especially across a multi-cloud, multi-platform infrastructure!

Link to query on Gist: https://gist.github.com/jksprattler/80519ade571714c4415e103ccc8ad2be

About the author

  • Hi there! I'm a Cloud Engineer & SRE, documenting my transition into AI/ML Platform Engineering. I write technical deep-dives, hands-on implementation guides, CLI helper scripts, and visual architectures covering cloud, infrastructure, orchestration, governance, and modern AI runtimes.

No comments yet. Be the first to comment.

MLOps & Reliability

Part 4 of 8

The automated workflows, observability, reliability engineering, and cost controls required to ship, monitor, and scale production systems sustainably. Covers IaC (Terraform), event-driven automations (Lambda, SES), CI/CD (GitHub Actions), FinOps, and more.

Up nextAzure AD & RBAC with Terraform Part 1This article was originally published in September 2022 on my GitHub io blog here Overview The purpose of this runbook is to demonstrate a potential approach to managing Azure AD users, groups and Ro

More from this blog