Important:
- To access BigQuery data in Google Sheets, you need access to BigQuery. Learn how to get started with BigQuery.
- You can only use Google standard SQL with the BigQuery connector.
- On your computer, open a spreadsheet in Google Sheets.
- In the menu at the top, click Data
Data connectors
Connect to BigQuery.
- Select a project.
- Click Saved queries and query editor.
- Enter a query.
- To preview how much data your query scans, in the bottom right of the editor, click Preview results.
- Click Insert results.
Tips:
- If you're a developer, learn how to use Apps Script with connected sheets.
- To find certain new saved queries, enable the Dataform API. Learn more about Dataform API.
- Validate data types between BigQuery and Sheets data for analysis.
To create queries in connected sheets, you can access saved queries from BigQuery projects. Learn more about saved queries.
- On your computer, open a spreadsheet in Google Sheets.
- In the menu, at the top of the spreadsheet, click Data
Data connectors
Connect to BigQuery.
- Select a project.
- Click Saved queries and query editor
BigQuery saved queries.
- Select a project
select a saved query.
- Click Connect.
To edit a saved query, update it directly within BigQuery. The updated query will appear in connected sheets within five minutes.
To keep your saved queries up to date whenever you update saved queries in BigQuery:
- In the connected sheet, sync your saved queries through Sync from BigQuery.
- In the 'BigQuery editor', click Connect.
Learn more about saved queries
When an error occurs due to a modified or deleted saved query, you can update the connection from the error dialogue or BigQuery editor.
- At the top right of the preview sheet, open Connection settings.
- To update the connection, click Sync from BigQuery
Connect.
- To update the connection for the following cases:
- Modified query: Click View error
Sync saved query.
- Or you can open the query editor. Click Edit
Sync saved query
Connect.
- Or you can open the query editor. Click Edit
- Deleted query: Click View error
Use as custom query.
- Or you can:
- To open the query editor, click Edit.
- Change to another query or unlink the existing query.
- Click Connect.
- Or you can:
- Modified query: Click View error
To use the value of a cell in a query, set up a parameter.
- At the right of the query editor, click Parameters
Add.
- Enter a parameter name and the cell you want to reference.
- Click Add.
If the data type in the spreadsheet and BigQuery are different, you can do the following:
- 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).
Sample queries
Simple query:
SELECT
word,
SUM(word_count) AS word_count
FROM
`bigquery-public-data.samples.shakespeare`
WHERE word IN ('me', 'I', 'you')
GROUP BY word;
Parameterised query:
SELECT SUM(kw_total)
FROM `bigquery-public-data.sunroof_solar.solar_potential_by_censustract`
WHERE state_name = @STATENAME;
Next: Fix problems with BigQuery data in Sheets