Analyze BigQuery data within Sheets
You can access and analyze your BigQuery data within Google Sheets using data connectors.
You can analyze and share large datasets from your spreadsheet with the BigQuery data connector. You can also use the data connector to:
- Collaborate with partners, analysts, or other stakeholders in a familiar spreadsheet interface.
- Ensure a single source of truth for data without having to create additional .csv exports.
- Streamline your reporting and dashboard workflows.
What you need
To connect with BigQuery, you’ll need one of the following account types:
- G Suite Business
- G Suite Enterprise
- G Suite for Education
- G Suite Enterprise for Education
- Drive Enterprise
The BigQuery data connector is only available for eligible work or school accounts, and you’re not signed in.
Step 1: Choose or add a billing project
To add or use a BigQuery project in Sheets, your project role in BigQuery must be:
- bigquery.user OR
- bigquery.jobUser and bigquery.dataViewer
Find a project
- On your computer, open a spreadsheet in Google Sheets.
- In the menu at the top, click Data Data connectors BigQuery.
- Under "Billing project," click Select a project.
- If you don’t find any projects, you need to add one.
Step 2: Write & edit a query
- After you choose or add a billing project, click Write query.
- In the query editor, enter a query.
- Note: To preview how much data your query scans, at the bottom right, click the Check mark .
- At the bottom right of the editor, click Insert results.
Note: There is a time limit for a query execution of 4 minutes and 30 seconds.
When you compare data in Sheets and BigQuery
To compare data, you might need to change the data type. For example, if a column is string data in BigQuery, then it must be plain text in Sheets to be compared correctly.
If the data type in the spreadsheet and BigQuery are different, you can:
- Change how the data is formatted in Sheets. For example, data formatted as number could be changed to plain text.
- Cast the value in a query. For example: WHERE zip_code = CAST(@ZIP AS string)
- When you run a query, your spreadsheet permissions are used, not the spreadsheet owner’s.
- You can pull up to 10,000 rows per query from BigQuery.
- Data that you pull from BigQuery is read-only.
- Only standard SQL is supported by BigQuery.
To use the value of a cell in a query, set up a parameter.
- At the right side of the query editor, click Parameters Add.
- Enter a name for the parameter and the cell you want to reference.
- Click Add.
Schedule a refresh of your query
Step 1: Record a macro to refresh your data
- On your computer, open a spreadsheet that contains data connected to BigQuery in Google Sheets.
- Record a macro from a different tab than the one you want to refresh.
- After you start recording, switch to the tab you want to refresh.
- At the bottom left, click Refresh.
- Click Save.
Step 2: Schedule your macro
- At the top, click Tools Script editor.
- At the top, click Edit Current project's triggers.
- At the bottom right, click Add trigger and select your options.
- Click Save.
SUM(word_count) AS word_count
WHERE word IN ('me', 'I', 'you')
GROUP BY word;
WHERE state_name = @STATENAME;
- With added parameter name set to ‘STATENAME’ and cell reference set to Sheet1!A3, which has the value of ‘New York’.
Change billing project or permissions
- In the query editor, at the right, click Query settings.
- Under "Billing project," choose a project.
The actions you can take depend on your project and spreadsheet permissions.
|User actions in Sheets||Required project role in BigQuery||Required permissions in Sheets|
|Create or edit the BigQuery query||bigquery.user OR bigquery.jobUser and bigquery.dataViewer||Owner, editor|
|View the BigQuery query||None||Owner, editor, viewer|
|Refresh data from a BigQuery query||bigquery.user OR bigquery.jobUser and bigquery.dataViewer||Owner, editor|
|See fetched data from a BigQuery query||None||Owner, editor, viewer|
- Queries are run using the user's spreadsheet permissions, not the spreadsheet owner's.
- Users outside the domain can only interact with a domain-owned-Sheet if the domain G Suite Administrator has allowed it.