Skip to main content

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

ParameterDescription
_aggAggregation type. Same set as aggregations.
_columnsSplits 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 'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name?_agg=max'

Pivot by multiple columns

Pass a comma-separated list of columns. The response is grouped by each unique combination.

curl 'https://api.sheetbest.com/sheets/YOUR_SHEET_ID/pivot/Name,Age?_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.