PivotGroup

Access and modify pivot table breakout groups.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#addManualGroupingRule(String,Object)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Adds a manual grouping rule for this pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#areLabelsRepeated()` | `Boolean` | Returns whether labels are displayed as repeated. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#clearGroupingRule()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Removes any grouping rules from this pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#clearSort()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Removes any sorting applied to this group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getDateTimeGroupingRule()` | `https://developers.google.com/apps-script/reference/spreadsheet/date-time-grouping-rule|null` | Returns the date-time grouping rule on the pivot group, or `null` if no date-time grouping rule is set. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getDimension()` | `https://developers.google.com/apps-script/reference/spreadsheet/dimension` | Returns whether this is a row or column group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getGroupLimit()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group-limit|null` | Returns the pivot group limit on the pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getIndex()` | `Integer` | Returns the index of this pivot group in the current group order. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getPivotTable()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-table` | Returns the `https://developers.google.com/apps-script/reference/spreadsheet/pivot-table` which this grouping belongs to. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getSourceDataColumn()` | `Integer` | Returns the number of the source data column this group summarizes. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#getSourceDataSourceColumn()` | `https://developers.google.com/apps-script/reference/spreadsheet/data-source-column|null` | Returns the data source column the pivot group operates on. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#hideRepeatedLabels()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Hides repeated labels for this grouping. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#isSortAscending()` | `Boolean` | Returns `true` if the sort is ascending, returns `false` if the sort order is descending. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#moveToIndex(Integer)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Moves this group to the specified position in the current list of row or column groups. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#remove()` | `void` | Removes this pivot group from the table. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#removeManualGroupingRule(String)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Removes the manual grouping rule with the specified `groupName`. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#resetDisplayName()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Resets the display name of this group in the pivot table to its default value. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#setDateTimeGroupingRule(DateTimeGroupingRuleType)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets the date-time grouping rule on the pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#setDisplayName(String)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets the display name of this group in the pivot table. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#setGroupLimit(Integer)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets the pivot group limit on the pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#setHistogramGroupingRule(Integer,Integer,Integer)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets a histogram grouping rule for this pivot group. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#showRepeatedLabels()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | When there is more than one row or column grouping, this method displays this grouping's label for each entry of the subsequent grouping. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#showTotals(Boolean)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets whether to show total values for this pivot group in the table. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#sortAscending()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets the sort order to be ascending. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#sortBy(PivotValue,Object)` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sorts this group by the specified `https://developers.google.com/apps-script/reference/spreadsheet/pivot-value` for the values from the `oppositeGroupValues`. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#sortDescending()` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` | Sets the sort order to be descending. |
| `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#totalsAreShown()` | `Boolean` | Returns whether total values are currently shown for this pivot group. |

## Detailed documentation

### `addManualGroupingRule(groupName, groupMembers)`

Adds a manual grouping rule for this pivot group.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `groupName` | `String` | The name of this grouping rule. |
| `groupMembers` | `Object[]` | The values that are included in this grouping rule. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `areLabelsRepeated()`

Returns whether labels are displayed as repeated.

#### Return


`Boolean` --- `true` if labels are repeated; otherwise returns `false`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `clearGroupingRule()`

Removes any grouping rules from this pivot group.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `clearSort()`

Removes any sorting applied to this group.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getDateTimeGroupingRule()`

Returns the date-time grouping rule on the pivot group, or `null` if no date-time
grouping rule is set.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/date-time-grouping-rule|null` --- The date-time grouping rule.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getDimension()`

Returns whether this is a row or column group.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/dimension` --- the dimension representing this group's type

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getGroupLimit()`

Returns the pivot group limit on the pivot group. Returns `null` if no pivot group limit
is set.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group-limit|null` --- The pivot group limit.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getIndex()`

Returns the index of this pivot group in the current group order.

#### Return


`Integer` --- the pivot group's index

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getPivotTable()`

Returns the `https://developers.google.com/apps-script/reference/spreadsheet/pivot-table` which this grouping belongs to.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-table` --- the pivot table this group belongs to.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getSourceDataColumn()`

Returns the number of the source data column this group summarizes. This index is 1-based, if
this group summarizes source data in column "A" of the spreadsheet this method returns `1`.

#### Return


`Integer` --- the source data column number

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getSourceDataSourceColumn()`

Returns the data source column the pivot group operates on. Returns `null` if the pivot
table is not a {DataSourcePivotTableApi}.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/data-source-column|null` --- The data source column the pivot group operates on.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `hideRepeatedLabels()`

Hides repeated labels for this grouping. If labels are already hidden this results in a no-op.
If this method is called before there are multiple row or column groupings, when an additional
grouping is added repeated labels are hidden.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `isSortAscending()`

Returns `true` if the sort is ascending, returns `false` if the sort order is
descending.

#### Return


`Boolean` --- `true` if the sort order is ascending.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `moveToIndex(index)`

Moves this group to the specified position in the current list of row or column groups. These
indices are 0-based. For example, if this group should be moved to the first position this
method should be called with `0`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `index` | `Integer` | The index to move this grouping to. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `remove()`

Removes this pivot group from the table.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `removeManualGroupingRule(groupName)`

Removes the manual grouping rule with the specified `groupName`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `groupName` | `String` | The name of the grouping rule to remove. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `resetDisplayName()`

Resets the display name of this group in the pivot table to its default value.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setDateTimeGroupingRule(dateTimeGroupingRuleType)`

Sets the date-time grouping rule on the pivot group.

To remove the rule, use `https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#clearGroupingRule()`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `dateTimeGroupingRuleType` | `https://developers.google.com/apps-script/reference/spreadsheet/date-time-grouping-rule-type` | The rule type to set. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- The pivot group, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setDisplayName(name)`

Sets the display name of this group in the pivot table.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | The display name to set. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setGroupLimit(countLimit)`

Sets the pivot group limit on the pivot group. The operation is only supported for `https://developers.google.com/apps-script/reference/spreadsheet/data-source-pivot-table`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `countLimit` | `Integer` | The count limit of rows or columns to set. Must be positive. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- The pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setHistogramGroupingRule(minValue, maxValue, intervalSize)`

Sets a histogram grouping rule for this pivot group. A histogram rule organizes values in a
source data column into buckets of a constant size. All values from `minValue` to `maxValue` are placed into groups of size `interval`. All values below `minValue`
are placed into one bucket, as are all values greater than `maxValue`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `minValue` | `Integer` | The minimum value for items to be placed into buckets. Values less than this are combined into a single bucket. |
| `maxValue` | `Integer` | The maximum value for items to be placed into buckets. Values greater than this are combined into a single bucket. |
| `intervalSize` | `Integer` |   |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `showRepeatedLabels()`

When there is more than one row or column grouping, this method displays this grouping's label
for each entry of the subsequent grouping. If labels are already repeated this results in a
no-op. If this method is called before there are multiple row or column groupings, when an
additional grouping is added repeated labels are shown.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `showTotals(showTotals)`

Sets whether to show total values for this pivot group in the table.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `showTotals` | `Boolean` | Whether to show totals or not. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `sortAscending()`

Sets the sort order to be ascending.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `sortBy(value, oppositeGroupValues)`

Sorts this group by the specified `https://developers.google.com/apps-script/reference/spreadsheet/pivot-value` for the values from the `oppositeGroupValues`.

```javascript
// Sorts the item group by the "SUM of Quantity" pivot value for the specified
// salespersons.
const sheet = SpreadsheetApp.getActiveSheet();
const pivotTable = sheet.getPivotTables()[0];
const itemGroup = pivotTable.getRowGroups()[0];
const sumQuantityValue = pivotTable.getPivotValues()[0];
itemGroup.sortBy(sumQuantityValue, ['Beth', 'Amir', 'Devyn']);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `value` | `https://developers.google.com/apps-script/reference/spreadsheet/pivot-value` | The pivot value to sort by. |
| `oppositeGroupValues` | `Object[]` | The values of an opposite pivot group (a column group if sorting a row group, or a row group if sorting a column group) that are used to sort. The order of these values determines precedence for tie breaking. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `sortDescending()`

Sets the sort order to be descending.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/pivot-group#` --- the pivot group for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `totalsAreShown()`

Returns whether total values are currently shown for this pivot group.

#### Return


`Boolean` --- `true` if total values are displayed for this pivot group; otherwise returns
`false`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`