Google Sheets Connector for SSAS
In this article you will learn how to integrate Using Google Sheets Connector you will be able to connect, read, and write data from within SSAS. Follow the steps below to see how we would accomplish that. The driver mentioned above is part of ODBC PowerPack which is a collection of high-performance Drivers for various API data source (i.e. REST API, JSON, XML, CSV, Amazon S3 and many more). Using familiar SQL query language you can make live connections and read/write data from API sources or JSON / XML / CSV Files inside SQL Server (T-SQL) or your favorite Reporting (i.e. Power BI, Tableau, Qlik, SSRS, MicroStrategy, Excel, MS Access), ETL Tools (i.e. Informatica, Talend, Pentaho, SSIS). You can also call our drivers from programming languages such as JAVA, C#, Python, PowerShell etc. If you are new to ODBC and ZappySys ODBC PowerPack then check the following links to get started. |
Connect to Google Sheets in other apps
|
Create Data Source in ZappySys Data Gateway based on API Driver
-
Download and install ZappySys ODBC PowerPack.
-
Search for gateway in start menu and Open ZappySys Data Gateway:
-
Go to Users Tab to add our first Gateway user. Click Add; we will give it a name tdsuser and enter password you like to give. Check Admin option and click OK to save. We will use these details later when we create linked server:
-
Now we are ready to add a data source. Click Add, give data source a name (Copy this name somewhere, we will need it later) and then select Native - ZappySys API Driver. Finally, click OK. And it will create the Data Set for it and open the ZS driver UI.
GoogleSheetsDSN
-
When the Configuration window appears give your data source a name if you haven't done that already, then select "Google Sheets" from the list of Popular Connectors. If "Google Sheets" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:
GoogleSheetsDSNGoogle Sheets -
Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.
User accounts represent a developer, administrator, or any other person who interacts with Google APIs and services. User accounts are managed as Google Accounts, either with Google Workspace or Cloud Identity. They can also be user accounts that are managed by a third-party identity provider and federated with Workforce Identity Federation. [API reference]
Steps how to get and use Google Sheets credentials
Follow these steps on how to create Client Credentials (User Account principle) to authenticate and access Google Sheets API in SSIS package or ODBC data source:
WARNING: If you are planning to automate processes, we recommend that you use a Service Account authentication method. In case, you still need to use User Account, then make sure you use a system/generic account (e.g.automation@my-company.com
). When you use a personal account which is tied to a specific employee profile and that employee leaves the company, the token may become invalid and any automated processes using that token will start to fail.Step-1: Create project
This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:
-
First of all, go to Google API Console.
-
Then click Select a project button and then click NEW PROJECT button:
-
Name your project and click CREATE button:
-
Wait until the project is created:
- Done! Let's proceed to the next step.
Step-2: Enable Google Cloud APIs
In this step we will enable Google Sheets API and Google Drive API:
-
Select your project on the top bar:
-
Then click the "hamburger" icon on the top left and access APIs & Services:
-
Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:
-
In the search bar search for
sheets
and then locate and select Google Sheets API: -
Then enable Google Sheets API:
-
Again, repeat the step and enable Google Drive API as well:
- Done! Let's proceed to the next step.
Step-3: Create OAuth application
-
First of all, click the "hamburger" icon on the top left and then hit VIEW ALL PRODUCTS:
-
Then access Google Auth Platform to start creating an OAuth application:
-
Start by pressing GET STARTED button:
-
Next, continue by filling in App name and User support email fields:
-
Choose Internal option, if it's enabled, otherwise select External:
-
Optional step if you used
Internal
option in the previous step. Nevertheless, if you had to useExternal
option, then click ADD USERS to add a user: -
Then add your contact Email address:
-
Finally, check the checkbox and click CREATE button:
- Done! Let's create Client Credentials in the next step.
Step-4: Create Client Credentials
-
In Google Auth Platform, select Clients menu item and click CREATE CLIENT button:
-
Choose
Desktop app
as Application type and name your credentials: -
Continue by opening the created credentials:
-
Finally, copy Client ID and Client secret for the later step:
- Done! We have all the data needed for authentication, let's proceed to the last step!
Step-5: Configure connection
-
Now go to SSIS package or ODBC data source and use previously copied values in User Account authentication configuration:
- In the ClientId field paste the Client ID value.
- In the ClientSecret field paste the Client secret value.
-
Press Generate Token button to generate Access and Refresh Tokens.
-
Open your Google Sheets spreadsheet in the browser, e.g.:
https://docs.google.com/spreadsheets/d/1QM6WmGloHeGCliCqV3nEj8P-R1RbS59t5xJutN99rU/edit
. -
Extract the spreadsheet Id from the URL and copy it to the clipboard, e.g.
1QM6WmGloHeGCliCqV3nEj8P-R1RbS59t5xJutN99rU
. -
Go back to authentication configuration window and paste it into Default SpreadsheetId field.
-
Finally, click Test Connection to confirm the connection is working.
-
Done! Now you are ready to use Google Sheets Connector!
Fill in all required parameters and set optional parameters if needed:
GoogleSheetsDSNGoogle SheetsUser Account [OAuth]https://sheets.googleapis.com/v4/spreadsheetsRequired Parameters UseCustomApp Fill-in the parameter... Scope Fill-in the parameter... Default SpreadSheetId Fill-in the parameter... Optional Parameters ClientId ClientSecret Default Tab Name (i.e. Sheet1) RetryMode RetryWhenStatusCodeMatch RetryStatusCodeList 403|429 RetryCountMax 5 Redirect URL (Only for Web App) Service accounts are accounts that do not represent a human user. They provide a way to manage authentication and authorization when a human is not directly involved, such as when an application needs to access Google Cloud resources. Service accounts are managed by IAM. [API reference]
Steps how to get and use Google Sheets credentials
Follow these steps on how to create Service Account to authenticate and access Google Sheets API in SSIS package or ODBC data source:
Step-1: Create project
This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:
-
First of all, go to Google API Console.
-
Then click Select a project button and then click NEW PROJECT button:
-
Name your project and click CREATE button:
-
Wait until the project is created:
- Done! Let's proceed to the next step.
Step-2: Enable Google Cloud APIs
In this step we will enable Google Sheets API and Google Drive API:
-
Select your project on the top bar:
-
Then click the "hamburger" icon on the top left and access APIs & Services:
-
Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:
-
In the search bar search for
sheets
and then locate and select Google Sheets API: -
Then enable Google Sheets API:
-
Again, repeat the step and enable Google Drive API as well:
- Done! Let's proceed to the next step.
Step-3: Create Service Account
Use the steps below to create a Service Account in Google Cloud:
-
First of all, go to IAM & Admin in Google Cloud console:
-
Once you do that, click Service Accounts on the left side and click CREATE SERVICE ACCOUNT button:
-
Then name your service account and click CREATE AND CONTINUE button:
-
Continue by clicking Select a role dropdown and start granting service account Project Viewer roles:
-
Find Project group and select Viewer role:
-
Finish adding roles by clicking CONTINUE button:
You can always add or modify permissions later in IAM & Admin. -
Finally, in the last step, just click button DONE:
-
Done! We are ready to add a Key to this service account in the next step.
Step-4: Add Key to Service Account
We are ready to add a Key (P12 certificate) to the created Service Account:
-
In Service Accounts open newly created service account:
-
Next, copy email address of your service account for the later step:
-
Continue by selecting KEYS tab, then press ADD KEY dropdown, and click Create new key menu item:
-
Finally, select P12 option and hit CREATE button:
- P12 certificate downloads into your machine. We have all the data needed for authentication, let's proceed to the last step!
Step-5: Configure connection
-
Now go to SSIS package or ODBC data source and use previously copied values in User Account authentication configuration:
- In the Service Account Email field paste the service account Email address value you copied in the previous step.
- In the Service Account Private Key Path (i.e. *.p12) field use downloaded certificate's file path.
-
Press Generate Token button to generate Access and Refresh Tokens.
-
Open your Google Sheets spreadsheet in the browser, e.g.:
https://docs.google.com/spreadsheets/d/1QM6WmGloHeGCliCqV3nEj8P-R1RbS59t5xJutN99rU/edit
. -
Extract the spreadsheet Id from the URL and copy it to the clipboard, e.g.
1QM6WmGloHeGCliCqV3nEj8P-R1RbS59t5xJutN99rU
. -
Go back to authentication configuration window and paste it into Default SpreadsheetId field.
-
Finally, click Test Connection to confirm the connection is working.
-
Done! Now you are ready to use Google Sheets Connector!
Fill in all required parameters and set optional parameters if needed:
GoogleSheetsDSNGoogle SheetsService Account [OAuth]https://sheets.googleapis.com/v4/spreadsheetsRequired Parameters Service Account Email Fill-in the parameter... Service Account Private Key Path (i.e. *.p12) Fill-in the parameter... Default SpreadSheetId Fill-in the parameter... Optional Parameters Scope https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/spreadsheets Default Tab Name (i.e. Sheet1) RetryMode RetryWhenStatusCodeMatch RetryStatusCodeList 403|429 RetryCountMax 5 Impersonate As (Enter Email Id) -
-
Once the data source has been configured, you can preview data. Select the Preview tab and use settings similar to the following to preview data:
-
Click OK to finish creating the data source.
Read Google Sheets data in SSAS cube
With the data source created in the Data Gateway (previous step), we're now ready to read Google Sheets data in an SSAS cube. Before we dive in, open Visual Studio and create a new Analysis Services project. Then, you're all set!
Create data source based on ZappySys Data Gateway
Let's start by creating a data source for a cube, based on the Data Gateway's data source we created earlier. So, what are we waiting for? Let's do it!
-
Create a new data source:
-
Once a window opens,
select Create a data source based on an existing or new connection option and
click New...:
-
Here things become a little complicated, but do not despair, it's only for a little while.
Just perform these little steps:
- Select Native OLE DB\SQL Server Native Client 11.0 as provider.
- Enter your Server name (or IP address) and Port, separated by a comma.
- Select SQL Server Authentication option for authentication.
- Input User name which has admin permissions in the ZappySys Data Gateway.
- In Database name field enter the same data source name you use in the ZappySys Data Gateway.
- Hopefully, our hard work is done, when we Test Connection.
GoogleSheetsDSNGoogleSheetsDSNIf SQL Server Native Client 11.0 is not listed as Native OLE DB provider, try using these:- Microsoft OLE DB Driver for SQL Server
- Microsoft OLE DB Provider for SQL Server
-
Indeed, life is easy again:
Add data source view
We have data source in place, it's now time to add a data source view. Let's not waste a single second and get on to it!
-
Start by right-clicking on Data Source Views and then choosing New Data Source View...:
-
Select the previously created data source and click Next:
- Ignore the Name Matching window and click Next.
-
Add the tables you will use in your SSAS cube:
For cube dimensions, consider creating a Virtual Table in the Data Gateway's data source. Use the
DISTINCT
keyword in theSELECT
statement to get unique values from the facts table, like this:SELECT DISTINCT Country FROM Customers
For demonstration purposes we are using sample tables which may not be available in Google Sheets. -
Review your data source view and click Finish:
-
Add the missing table relationships and you're done!
Create cube
We have a data source view ready to be used by our cube. Let's create one!
-
Start by right-clicking on Cubes and selecting New Cube... menu item:
-
Select tables you will use for the measures:
-
And then select the measures themselves:
-
Don't stop and select the dimensions too:
-
Move along and click Finish before the final steps:
-
Review your cube before processing it:
-
It's time for the grand finale! Hit Process... to create the cube:
-
A splendid success!
Execute MDX query
The cube is created and processed. It's time to reap what we sow! Just execute an MDX query and get Google Sheets data in your SSAS cube:

Advanced topics
Create Custom Stored Procedure in ZappySys Driver
You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.
Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here
-
Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
-
Enter the desired Procedure name and click on OK:
-
Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver:
Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here
CREATE PROCEDURE [usp_get_orders] @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>' AS SELECT * FROM Orders where OrderDate >= '<@fromdate>';
-
That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:
Exec usp_get_orders '1996-01-01';
-
Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.
SELECT * FROM OPENQUERY([MY_API_SERVICE], 'EXEC usp_get_orders @fromdate=''1996-07-30''')
-
Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
Create Custom Virtual Table in ZappySys Driver
ZappySys API Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you don't have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.
If you're dealing with Microsoft Access and need to import data from an SQL query, it's important to note that Access doesn't allow direct import of SQL queries. Instead, you can create custom objects (Virtual Tables) to handle the import process.
Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.
-
Go to Custom Objects Tab and Click on Add button and Select Add Table:
-
Enter the desired Table name and click on OK:
-
And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.
-
Select the created table, Select Text Type AS SQL and write the your desired SQL Query and Save it and it will create the custom table in the ZappySys Driver:
Here is an example SQL query for ZappySys Driver. You can insert Placeholders also. Read more about placeholders here
SELECT "ShipCountry", "OrderID", "CustomerID", "EmployeeID", "OrderDate", "RequiredDate", "ShippedDate", "ShipVia", "Freight", "ShipName", "ShipAddress", "ShipCity", "ShipRegion", "ShipPostalCode" FROM "Orders" Where "ShipCountry"='USA'
-
That's it now go to Preview Tab and Execute your custom virtual table query. In this example it will extract the orders for the USA Shipping Country only:
SELECT * FROM "vt__usa_orders_only"
-
Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.
SELECT * FROM OPENQUERY([MY_API_SERVICE], 'EXEC [usp_get_orders] ''1996-01-01''')
-
Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
Actions supported by Google Sheets Connector
Google Sheets Connector support following actions for REST API integration. If some actions are not listed below then you can easily edit Connector file and enhance out of the box functionality.Parameter | Description |
---|---|
Range |
|
Parameter | Description |
---|---|
Range |
|
Parameter | Description | ||||||
---|---|---|---|---|---|---|---|
Range Type |
|
||||||
Range Start Index (starts from 0) |
|
||||||
Range End Index (starts from 0) |
|
||||||
TabId |
|
Parameter | Description |
---|---|
TabId |
|
Parameter | Description |
---|---|
NewTabName |
|
InitialRowCount |
|
InitialColumnCount |
|
TabColorRedValue |
|
TabColorGreenValue |
|
TabColorBlueValue |
|
Parameter | Description |
---|---|
Request Body |
|
TabId |
|
Parameter | Description |
---|---|
Range for Table Boundary (Including Header) |
|
Range for Data Cells |
|
Parameter | Description |
---|---|
Start Range |
|
Parameter | Description | ||||||
---|---|---|---|---|---|---|---|
SpreadSheetId |
|
Parameter | Description | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Url |
|
||||||||||||||||||||||||||
Body |
|
||||||||||||||||||||||||||
IsMultiPart |
|
||||||||||||||||||||||||||
Filter |
|
||||||||||||||||||||||||||
Headers |
|
Parameter | Description |
---|---|
Url |
|
IsMultiPart |
|
Filter |
|
Headers |
|
Google Sheets Connector Examples for SSAS Connection
This page offers a collection of SQL examples designed for seamless integration with the ZappySys API ODBC Driver under ODBC Data Source (36/64) or ZappySys Data Gateway, enhancing your ability to connect and interact with Prebuilt Connectors effectively.
Query from default Spreadsheet [Read more...]
Gets data from Tab name Sheet1 from SpreadSheet Id defined in the connection
SELECT * FROM [Sheet1]
Query from User defined Spreadsheet [Read more...]
Gets data from Tab name 'Class Data' from user defined SpreadSheet Id
SELECT * FROM [Class Data] WITH(SpreadSheetId='1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms')
Query from custom cell range [Read more...]
In this example we query Tab name 'Class Data' and we are reading Range 'A4:GR'.
SELECT * FROM [Class Data]
WITH(
Range='A4:GR' --cell range you like to query
, ArrayTransEnableCustomColumns='False' --do not treat first row in range as Column Names
, SpreadSheetId='1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms' --enter sheet id you like to query. Comment this if you like to use default ID defined in the connection
)
Query from custom cell range [Read more...]
In this example we query Tab name 'Class Data' and we are reading Range 'A4:GR'.
UPDATE [Sheet1]
SET Col1='data-1', Col2=100, Col3='2020-01-31' --column names are ignored. Values are sent in the same order you supply and writtern to start cell specified by WriteRange
WITH(
, WriteRange='G9' --start writing from here
, SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU' --comment this to use default Sheet Id from connection setting
)
Update Multiple Rows in Sheet from CSV file [Read more...]
In this example we query CSV file as Source (Using ZapyySys CSV ODBC Driver) and updating Google Sheet in BULK.
UPDATE [Sheet1]
SOURCE(
'ODBC', --driver type ODBC | MSSQL | OLEDB
'Driver={ZappySys CSV Driver};', --connection string for driver
'SELECT * FROM $ WITH (SRC=''c:\data.csv'') ' --sql query for source data
)
WITH(
WriteRange='G9', SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU' --comment this to use default Sheet Id from connection setting
)
Update Values Vertically (Column Mode) [Read more...]
In this example we will write value as columns rather than row.
UPDATE [Sheet1]
SET Col1='Jan',Col2='Feb',Col3='Mar'
WITH(
WriteRange='G9',
SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU', --comment this to use default Sheet Id from connection setting
MajorDimension='COLUMNS' --write values vertical rather horizontal
)
Insert Data in Sheet1 [Read more...]
Insert row to tab name Sheet1 in SheetId defined in connection
INSERT INTO "Sheet1"("MyStringCol", "MyIntegerCol", "MyDateCol", "MyDecimalCol") VALUES('AAA',100,'2020-01-01',150.33)
Insert Multiple Rows in Sheet1 from CSV file [Read more...]
In this example we query CSV file as Source (Using ZapyySys CSV ODBC Driver) and updating Google Sheet in BULK.
INSERT INTO [Sheet1]
SOURCE(
'ODBC', --driver type ODBC | MSSQL | OLEDB
'Driver={ZappySys CSV Driver};', --connection string for driver
'SELECT * FROM $ WITH (SRC=''c:\temp\dump.txt'') ' --sql query for source data
)
WITH(
Range='G9', SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU' --comment this to use default Sheet Id from connection setting
)
Write Values Vertically (Column Mode) [Read more...]
In this example we will write value as columns rather than row.
INSERT INTO [Sheet1](Col1,Col2,Col3)
VALUES('Jan','Feb','Mar')
WITH(
Range='G9', --starting cell to write data
SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU', --comment this to use default Sheet Id from connection setting
MajorDimension='COLUMNS' --write values vertical rather horizontal
)
Execute Action (i.e. Delete Rows / Columns) [Read more...]
This example shows how to execute various commands for sheet (i.e. copy, paste, formatting, delete, merge etc). In this example we are executing delete comamnds (i.e. deleteDimension commands). Notice we called same command twice becuase we want to delete two ranges (index 10-20 and 50-60). You can execute any valid command available by Google Sheets API. Here are some good examples of formatting commands https://developers.google.com/sheets/api/samples/formatting
SELECT * FROM batch_update_request
WITH(
Body='{
"requests": [
{
"deleteDimension": {
"range": {
"sheetId": 0,
"dimension": "ROWS",
"startIndex": 10,
"endIndex": 20
}
}
} ,
{
"deleteDimension": {
"range": {
"sheetId": 0,
"dimension": "ROWS",
"startIndex": 50,
"endIndex": 60
}
}
}
]
}'
, TabId='0' -- tab internal id (use UI to get this). 0 means first tab. Or check URL in browser and see at the end of URL #gid=xxxxxxx where xxxxxx is your tab id
, SpreadSheetId='1az2H8ZYk7BvjddVTqPR-LfDjX9IRpIpjCDpFPe9EzkU' --comment this to use default Sheet Id from connection setting
)
Conclusion
In this article we discussed how to connect to Google Sheets in SSAS and integrate data without any coding. Click here to Download Google Sheets Connector for SSAS and try yourself see how easy it is. If you still have any question(s) then ask here or simply click on live chat icon below and ask our expert (see bottom-right corner of this page).
Download Google Sheets Connector for SSAS
Documentation
More integrations
Other application integration scenarios for Google Sheets
Other connectors for SSAS
Download Google Sheets Connector for SSAS
Documentation
How to connect Google Sheets in SSAS?
How to get Google Sheets data in SSAS?
How to read Google Sheets data in SSAS?
How to load Google Sheets data in SSAS?
How to import Google Sheets data in SSAS?
How to pull Google Sheets data in SSAS?
How to push data to Google Sheets in SSAS?
How to write data to Google Sheets in SSAS?
How to POST data to Google Sheets in SSAS?
Call Google Sheets API in SSAS
Consume Google Sheets API in SSAS
Google Sheets SSAS Automate
Google Sheets SSAS Integration
Integration Google Sheets in SSAS
Consume real-time Google Sheets data in SSAS
Consume real-time Google Sheets API data in SSAS
Google Sheets ODBC Driver | ODBC Driver for Google Sheets | ODBC Google Sheets Driver | SSIS Google Sheets Source | SSIS Google Sheets Destination
Connect Google Sheets in SSAS
Load Google Sheets in SSAS
Load Google Sheets data in SSAS
Read Google Sheets data in SSAS
Google Sheets API Call in SSAS