Write & edit a query

If you want to perform more complex analyses (e.g. join data from more than one BigQuery table), you can write a custom query.

Important:

  1. On your computer, open a spreadsheet in Google Sheets.
  2. In the menu at the top, click Data and then Data connectors and then Connect to BigQuery.
  3. Choose a project.
  4. Click Write a custom query.
  5. Enter a query.
    • To preview how much data your query scans, in the bottom right of the editor, click Preview results.
  6. Click Insert results.
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.
Add parameters to your query

To use the value of a cell in a query, set up a parameter.

  1. At the right of the query editor, click Parameters and then Add.
  2. Enter a parameter name and the cell you want to reference.
  3. Click Add.
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 do the following:

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

true
Visit the Learning Center

Using Google products, like Google Docs, at work or school? Try powerful tips, tutorials, and templates. Learn to work on Office files without installing Office, create dynamic project plans and team calendars, auto-organize your inbox, and more.

Search
Clear search
Close search
Google apps
Main menu
6962213345997201414
true
Search Help Centre
true
true
true
true
true
35
false
false