> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costory.io/llms.txt
> Use this file to discover all available pages before exploring further.

# BigQuery

> Query BigQuery tables live as external metrics in Costory Advanced Explorer. Grant dataset access, validate the project, then pick a table.

Query BigQuery tables live as external metrics in [Advanced Explorer](https://docs.costory.io/setup/usage-metrics#query-after-you-connect). Grant dataset-level access to the Costory service account, validate the project, then pick a table, date field, and value column. Costory does not copy table data.

On **Add integration**, the **GCP** tile lists **Any BigQuery table**, **Cloud Monitoring metrics**, and **BigQuery jobs**. This page is **BigQuery Metric**: live queries against a table. For per-query dimensions on the GCP bill, see [BigQuery jobs](https://docs.costory.io/setup/usage-metrics/bigquery-jobs.md). For live GCP infrastructure metrics, see [GCP Cloud Monitoring](https://docs.costory.io/setup/usage-metrics/gcp-cloud-monitoring.md).

[BigQuery external metrics and Costory integration demo](https://www.youtube.com/embed/feK5VErY4UQ)

See BigQuery integration and cost allocation in action

![Connect GCP BigQuery page with dataset access steps and project ID field](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-bigquery.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=3bee554a9c8b79fa681c3fe6cc81cf9f)

Connect GCP BigQuery: grant dataset access on the left, Connection details on the right

> [tab] Manual setup
>
> **1. Open the GCP tile**
>
> Go to [Integrations](https://app.costory.io/integration), click **+ Add integration**, then under **External metric** choose **GCP**. The connect URL is `/integration/new/gcp/bigquery`.&#x20;
>
> **2. Grant dataset access**
>
> Copy the Costory service account from the connect screen. Open the BigQuery dataset you want Costory to read, share it with that account, and grant **BigQuery Data Viewer** and **BigQuery Metadata Viewer** on the whole dataset, not on individual tables. Project-level access is not required.
>
> These are the same roles used for [GCP billing export](https://docs.costory.io/setup/billing/gcp.md).
>
> **3. Enter connection details**
>
> Set **Connection name** and **GCP project ID**. Click **Validate**, then **Save connection**.
>
> > [!NOTE]
> >
> > This connector queries usage metrics from your BigQuery tables. To import GCP billing data, use [GCP Billing Setup](https://docs.costory.io/setup/billing/gcp.md). To export Costory dashboard data to your own BigQuery project, see [BigQuery Data Exports](https://docs.costory.io/setup/destinations/bigquery.md).
>
> > [!TIP]
> >
> > An EU organization can use a US dataset if it has an EU replica. Analytics Hub linked datasets in the project are included. Share the linked dataset, not the publisher dataset.
>
> ## Example table schema
>
> Your table needs a date column and at least one numeric metric column. Optional string columns work as group-by dimensions.
>
> ```sql theme={null}
> CREATE TABLE `my-project.analytics.daily_active_users` (
>   usage_date DATE,
>   product STRING,
>   active_users INT64
> );
> ```
>
> Common metrics to query:
>
> * Product analytics: daily or monthly active users, sessions, sign-ups
> * Business KPIs: revenue, orders, customers, emails sent
> * Application usage: API calls, background jobs, feature usage counts
> * Data platform activity: query counts, bytes processed, or slot hours per team or project
>
> ## Table requirements
>
> | Requirement | Details |
> | - | - |
> | **Region** | Tables must be in the same region as your Costory workspace. Costory uses **EU** by default and **US** for US-based organizations. Multi-region locations (`EU`, `US`) work. Single-region datasets are not supported because BigQuery can only query tables in the exact same location. Replicate data to `EU` or `US` with [BigQuery data replication](https://cloud.google.com/bigquery/docs/data-replication) if needed. An EU organization can use a US dataset if it has an EU replica. |
> | **Numeric column** | At least one numeric column, such as `FLOAT64`, `NUMERIC`, or `BIGNUMERIC`. |
> | **Date column** | At least one date or timestamp column: `DATE`, `DATETIME`, or `TIMESTAMP`. |
>
> ## Query after you connect
>
> Queries run live. Costory does not copy table data.
>
> **1. Open Advanced Explorer**
>
> Click **Explore your data**, then switch **Classic** to **Advanced**. Classic greys out non-cost metrics.
>
> **2. Add the BigQuery metric**
>
> Click **+ Add Metric**. Use the **integrations** chip, then pick **BigQuery**. Helper text describes it as a live external usage metric.
>
> ![Advanced Explorer metric picker open on Cost, with integrations listing Tsuga and BigQuery](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/explorer-metric-picker.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=83a364e7392e46a8df87ec385843e3f9)
>
> Metric picker chips: cost, usage, metric, budget, and integrations
>
> **3. Choose a table and columns**
>
> Pick a **table** from the picker, then set **Date field**, **Value column**, **Aggregate** (**SUM**), **Gap fill** (**FORWARD FILL**, **ZERO**, or **LINEAR**), and optional **Group by**.
>
> ![Select metric dropdown listing BigQuery tables such as demo\_raw.artifact\_registry and demo\_raw.aws\_ec2](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/explorer-table-picker.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=72f9ac21292f4f27c3ab6d0382e60619)
>
> BigQuery table picker after you select the BigQuery integration
>
> **4. Fix an empty chart**
>
> If the chart is empty, pick a different table and change **Period**. Options include Custom dates, Trailing 7 / 30 / 45 / 90 Days, MTD, QTD, YTD, Last Week, Last Month, Last 3 / 6 / 12 months, and Last Invoice Month.
>
> ![Advanced Explorer Period menu listing Custom dates, trailing ranges, MTD, QTD, YTD, and Last Invoice Month](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/explorer-period-dropdown.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=7c5f901ae6651511c71163f3bb3254c2)
>
> Period dropdown with Trailing 45 Days selected
>
> In the demo workspace, `demo_raw.artifact_*` tables stayed empty at every range. `demo_raw.raw_v2` with **Trailing 90 Days** rendered using date `billing_period_end`, value `billed_cost`, **SUM**, and **FORWARD FILL**.
>
> ![Advanced Explorer bar chart of Externalmetric from BigQuery demo\_raw.raw\_v2 over Trailing 90 Days](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/explorer-chart-raw-v2.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=ee158e91580b31d7e8b0ddf9a5685f1c)
>
> External metric chart for demo\_raw\.raw\_v2 with billed\_cost SUM and FORWARD FILL
>
> **5. Add cost or a formula**
>
> Optionally click **+ Add Metric** for **Cost**, then **+ Add Formula** such as `b / a`.
>
> ## Metric configuration
>
> | Field | Description |
> | - | - |
> | **Table** | The BigQuery table to read. |
> | **Date field** | Column used for the time series. |
> | **Value column** | Column with the metric value. |
> | **Aggregate** | How values are rolled up. Use **SUM** unless you have a reason to pick another aggregate. |
> | **Gap fill** | How missing dates are filled: **FORWARD FILL**, **ZERO**, or **LINEAR**. |
> | **Group by** | Optional dimension column to split the metric (for example team, product, or environment). |
>
> Use the series in a [virtual dimension (Rule-based dimensions that map cloud resources to business groupings like teams, products, or environments.)](https://docs.costory.io/features/tagging/dimensions.md#virtual-dimensions) or [shared cost allocation](https://docs.costory.io/features/tagging/shared-cost-allocation.md) rule after you can query it in Explorer.
>
> See [Unit Economics](https://docs.costory.io/features/unit-economics.md) for formula examples, or [BigQuery cost visibility with dbt](https://docs.costory.io/use-cases/dbt_bigquery_visibility/increase_visibility.md) for attributing warehouse spend by model or team.
>
> ## Troubleshooting
>
> | Issue | What to check |
> | - | - |
> | **Table does not appear** | Confirm the dataset is shared with the Costory service account on the whole dataset, the table has both a date and numeric column, and the dataset region matches your Costory workspace (or has an EU replica for an EU org). For Analytics Hub, share the linked dataset, not the publisher dataset. |
> | **Chart is empty** | Pick a different table and change **Period**. In the demo workspace, `demo_raw.artifact_*` stayed empty. `demo_raw.raw_v2` with **Trailing 90 Days** rendered. |
> | **Wrong date or value column selected** | Open the metric configuration and pick the correct columns. |
> | **Dataset is in a single region** | Replicate the dataset to `EU` or `US` with [BigQuery data replication](https://cloud.google.com/bigquery/docs/data-replication). |

> [tab] Terraform
>
> Not supported.

## Related pages

> [card] [GCP Cloud Monitoring](https://docs.costory.io/setup/usage-metrics/gcp-cloud-monitoring.md)
>
> Query live GCP metrics on the same GCP tile.

> [card] [Unit Economics](https://docs.costory.io/features/unit-economics.md)
>
> Combine BigQuery metrics with cloud cost in Explorer formulas.

> [card] [Shared Cost Allocation](https://docs.costory.io/features/tagging/shared-cost-allocation.md)
>
> Split shared infrastructure costs using BigQuery usage metrics.

> [card] [Metrics Correlation](https://docs.costory.io/setup/usage-metrics)
>
> Browse all supported external metric sources.

> [card] [BigQuery and dbt visibility](https://docs.costory.io/use-cases/dbt_bigquery_visibility/increase_visibility.md)
>
> Attribute BigQuery spend by dbt model, package, or team.

> [card] [BigQuery jobs (beta)](https://docs.costory.io/setup/usage-metrics/bigquery-jobs.md)
>
> Reallocate slots to the user who ran the query. One view of on-demand and reservations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.