Pivoting Data
The /pivot/<Column Names> endpoint groups rows by one or more columns and applies an aggregation across the rest. Combined with _agg and _columns, it lets you build summaries directly from the API.
Parameters
| Parameter | Description |
|---|---|
_agg | Aggregation type. Same set as aggregations. |
_columns | Splits pivoted groups using the listed columns |
_agg accepts: sum, prod, max, min, mean, median, std, var, any, all.
Pivot by a single column
Group rows by Name and aggregate the remaining columns with max.
- cURL
- JavaScript
- Python
curl 'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name?_agg=max'
fetch(
'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name?_agg=max'
);
import requests
requests.get(
'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name',
params={'_agg': 'max'},
)
Pivot by multiple columns
Pass a comma-separated list of columns. The response is grouped by each unique combination.
- cURL
- JavaScript
- Python
curl 'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name,Age?_agg=max'
fetch(
'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name,Age?_agg=max'
);
import requests
requests.get(
'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name,Age',
params={'_agg': 'max'},
)
Splitting groups with _columns
Use _columns to split the pivoted groups by additional columns.
curl 'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name?_agg=mean&_columns=Department'
Notes
- The aggregation list mirrors aggregations; values that cannot be aggregated by the chosen operation are skipped.
- To compute a single aggregation across the whole sheet without grouping, use
/agg/<operation>instead.