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.
- Choose a project.
- Click Write a custom query.
- Enter a query.
- To preview how much data your query scans, in the bottom right of the editor, click Preview results.
- Click Insert results.
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
Related articles
Get started with BigQuery data in Sheets
Sort & filter your BigQuery data in Sheets
Analyse & refresh a query with BigQuery data in Sheets
Fix problems with BigQuery data in Sheets