Class DataSourcePivotTable Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Use this class to access and modify existing data source pivot tables, exclusively with data connected to a database.
You can add column groups, filters, and pivot values to the data source pivot table.
Methods are available to refresh, force refresh, cancel refresh, and check the status of the data source pivot table.
The
asPivotTable()method allows you to return the data source pivot table as a regular pivot table object.
Access and modify existing data source pivot table. To create a new data source pivot table, useRange.createDataSourcePivotTable(dataSource).
Only use this class with data that's connected to a database.
Methods
| Method | Return type | Brief description |
|---|---|---|
add | Pivot | Adds a new pivot column group based on the specified data source column. |
add | Pivot | Adds a new filter based on the specified data source column with the specified filter criteria. |
add | Pivot | Adds a new pivot value based on the specified data source column without any summarizefunction. |
add | Pivot | Adds a new pivot value based on the specified data source column with the specified summarizefunction. |
add | Pivot | Adds a new pivot row group based on the specified data source column. |
as | Pivot | Returns the data source pivot table as a regular pivot table object. |
cancel | Data | Cancels the data refresh associated with this object if it's currently running. |
force | Data | Refreshes the data of this object regardless of the current state. |
get | Data | Gets the data source the object is linked to. |
get | Data | Gets the data execution status of the object. |
refresh | Data | Refreshes the data of the object. |
wait | Data | Waits until the current execution completes, timing out after the provided number of seconds. |
Detailed documentation
addColumnGroup(columnName)
Adds a new pivot column group based on the specified data source column.
Parameters
| Name | Type | Description |
|---|---|---|
column | String | The data source column name the pivot group is based on. |
Return
Pivot — The new pivot group.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
addFilter(columnName, filterCriteria)
Adds a new filter based on the specified data source column with the specified filter criteria.
Parameters
| Name | Type | Description |
|---|---|---|
column | String | The data source column name the filter is based on. |
filter | Filter | The criteria the filter uses. |
Return
Pivot — The new filter.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
addPivotValue(columnName)
Adds a new pivot value based on the specified data source column without any summarizefunction. For Looker measures only.
The following code shows how you can add a Looker measure as a pivot value.
// TODO(developer): Replace with your spreadsheet ID which has a Looker data// source.constspreadsheet=SpreadsheetApp.openById('abcd1234');constdatasource=spreadsheet.getDataSources()[0];constpivotTable=datasource.createDataSourcePivotTableOnNewSheet();pivotTable.addPivotValue('columnName');
This method is only available for Looker data sources.
Parameters
| Name | Type | Description |
|---|---|---|
column | String | The data source column name the pivot value is based on. |
Return
Pivot — The new pivot value.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
addPivotValue(columnName, summarizeFunction)
Adds a new pivot value based on the specified data source column with the specified summarizefunction.
In order to add pivot values for Looker measures, useadd.
Parameters
| Name | Type | Description |
|---|---|---|
column | String | The data source column name the pivot value is based on. |
summarize | Pivot | The summarize function the pivot value uses. |
Return
Pivot — The new pivot value.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
addRowGroup(columnName)
Adds a new pivot row group based on the specified data source column.
Parameters
| Name | Type | Description |
|---|---|---|
column | String | The data source column name the pivot group is based on. |
Return
Pivot — The new pivot group.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
asPivotTable()
Returns the data source pivot table as a regular pivot table object.
Return
Pivot — The pivot table.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
cancelDataRefresh()
Cancels the data refresh associated with this object if it's currently running.
This example shows how to cancel a formula refresh.
constspreadsheet=SpreadsheetApp.getActive();constformula=spreadsheet.getDataSourceFormulas()[0];// Cancel the ongoing refresh on the formula.formula.cancelDataRefresh();
Throws an exception if the data source type is not enabled. UseSpreadsheet methods to enable data execution for specific data sourcetype.
Return
Data — The data object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
forceRefreshData()
Refreshes the data of this object regardless of the current state. Seerefresh formore details. If you want to cancel a currently running refresh of this object, seecancel.
Throws an exception if the data source type is not enabled. UseSpreadsheet methods to enable data execution for specific data sourcetype.
Return
Data — The data object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getDataSource()
Gets the data source the object is linked to.
Return
Data — The data source.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getStatus()
Gets the data execution status of the object.
Return
Data — The data execution status.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
refreshData()
Refreshes the data of the object.
Throws an exception if currently inerror state. UseData to update the specification. The method ispreferred overforce to prevent unexpected edits on data source.
Throws an exception if the data source type is not enabled. UseSpreadsheet methods to enable data execution for specific data sourcetype.
Return
Data — The data object.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
waitForCompletion(timeoutInSeconds)
Waits until the current execution completes, timing out after the provided number of seconds.Throws an exception if the execution is not completed when timing out, but does not cancel thedata execution.
Parameters
| Name | Type | Description |
|---|---|---|
timeout | Integer | The time to wait for data execution, in seconds. The maximum is 300 seconds. |
Return
Data — The data execution status.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.