DATA INTEGRATION
DATA ACTIVATION
EMBEDDED DATA CLOUD
Popular database connectors
Popular SaaS connectors
SOFTWARE COMPANIES
ACCOUNTING & CONSULTANCY
ENTERPRISE
TECH COMPANIES
A Snowflake data warehouse is often used to provide data for a BI tool such as Microsoft Power BI, Tableau, Qlik, Looker or Metabase to perform data analytics, build dashboards with charts and reports. While BI tools provide many advantages, it is often also desired to make data from the data warehouse available in a spreadsheet such as Google Sheets.
In this article we will discuss how Snowflake can be used in combination with Google Sheets. We’ll discuss how to connect Google Sheets files to Snowflake, and how to write data from Snowflake into Google Sheets. We’ll talk about practical and organizational implications, as well as how to set up a technical implementation with e.g. low-code Python scripts.
Google Sheets can be used to deliver data from Snowflake (or any other data warehouse) to business teams, allowing them to build their own reports, perform ad hoc analysis, and work with the data in a self-service manner. Often this is the optimal solution to enable self-service analytics. This approach is also referred to as “Spreadsheet-based BI”.
Writing data to Google Sheet files using a script allows for more flexibility, compared to an ETL pipeline. We’ll use Python to show how to write data, using the Peliqan low-code pip module, which provides wrapper functions for the Google Sheets API. It abstracts away the complexity of handling the API (oAuth authorization, handling paging, handling error codes, building up POST payload bodies in JSON etc.).
Example Python script to open a Google Sheets file and write rows by appending at the bottom of the sheet:
from peliqan import Peliqan
# Sign up for a free Peliqan.io account; in Admin > Security settings > API token
jwt = "MY_JWT_TOKEN"
pq = Peliqan(jwt)
# Add a connection to Google Sheets first (oAuth) under My Connections
Sheets = pq.connect('Google Sheets Writeback')
data = [
["abc", "def"],
[123, 456]
]
result = Sheets.add("rows",
spreadsheet_id = "...",
sheet = "Sheet1",
values = data)
from peliqan import Peliqan
# Sign up for a free Peliqan.io account; in Admin > Security settings > API token
jwt = "MY_JWT_TOKEN"
pq = Peliqan(jwt)
# connect to your data warehouse
dw = pq.dbconnect('Snowflake')
# fetch a table in Peliqan as dataframe (DF)
# replace missing values with an empty string
df = dw.fetch("mydb", "invoices", df=True, fillna_with='')
# convert DF to a list, needed for Google Sheets
rows = df.values.tolist()
Sheets = pq.connect("Google Sheets Writeback")
Sheets.update("rows",
spreadsheet_id = "...",
sheet = "Sheet1",
row = 4,
column = "A",
values = rows)
Sheets = pq.connect("Google Sheets Writeback")
result = Sheets.delete('sheet_values',
spreadsheet_id = "...",
sheet = "Sheet1")
A good practice is to write your data to separate sheets (the “data sheets”) in Google Sheets that you label as read-only. This allows you to clear the entire sheet before writing a new update of the data, making sure that no data from a previous run is still present in the Google Sheets. In the actual reporting sheets, you can use the VLOOKUP formula to look up the required values.
A common issue with VLOOKUP is that it can only look up values using one lookup column and not a combination of columns. Therefore you might have to add a “lookup” column in the data sheet which concatenates multiple cells.
Here’s a basic example, the report uses a VLOOKUP which concatenates the different lookup values (product & city):
This is the VLOOKUP formula that is used in the above report:
=vlookup(C$2&$A4,’data sheet’!$A$2:$D$5,4,false)
And here is the “data sheet” (or “lookup sheet”), where a lookup column — in grey — has been added, which also concatenates the different dimension columns:
This is the formula that is used to build up the above “Lookup value” column by concatenating two columns: =B5&C5
#Roll up by date
SELECT date, sum(value) FROM purchase_orders
GROUP BY date
#Roll up by product
SELECT product_id, product_name, sum(value) FROM purchase_orders
GROUP BY product_id, product_name
Google Sheets is an excellent tool to build personalized reports for business users, because it’s a tool that many people are comfortable with, to dive into the data and do their own analysis. This concept is also called “Spreadsheet BI” and an excellent alternative to deliver data from your Snowflake data warehouse to business teams. A low-code platform such as Peliqan.io makes it easy to sync data from Snowflake into Google Sheets.
Syncing data into Google Sheets is just one of many Data Activation use cases that Peliqan.io enables.