# pivottable: Pivottable Spreadsheet Function for an Array

> pivottable (Pivottable Spreadsheet Function for an Array) is a 1001fx API function in the group Spreadsheet: POST https://api.1001fx.com/spreadsheet/pivottable, 2 credits per call. It works as a ready-made module in Make and n8n or as a plain HTTP call.

Implements a pivottable function similar to GSheet and Excel functions. Aggregate fields with given operator. Multiple fields can be aggregated. Aggregate functions are: count, sum, min, max and mean.

 Aggregate functions : 
- count: calculates the count of all values in a set 
- sum: calculates the sum of values. 
- min: minimum gets the minimum value in a set of values
- max: aximum gets the maximum value in a set of values
- mean: calculates the average in a set of values — not rounded

- Group: Spreadsheet
- Endpoint: `POST https://api.1001fx.com/spreadsheet/pivottable`
- Authentication: header `X-API-KEY: YOURSECRETAPIKEY`
- Content type: application/json
- Credits: 2 credits per call
- Ready-made in: Make and n8n
- Docs: https://1001fx.com/functions/pivottable

## Parameters

- `data` (array<object>, required) – Data: Array of objects with at least two properties e.g. [{city,score}] each.
- `index` (string, required) – Index: Name of the field in data to be used as index for aggregation. Case sensitive.
- `aggregateFunctions` (array<object>, required) – Aggregate functions: Aggregate operator per name attribute.
  - `field` (string, required) – Field: Name of field
  - `aggregators` (array<enum>, required, one of `count`, `sum`, `min`, `max`, `mean`) – Aggregators: Aggregator functions

## Example: Single aggregation

```bash
curl -X POST 'https://api.1001fx.com/spreadsheet/pivottable' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"data":[{"name":"Alice","score":1,"highest":10},{"name":"Bob","score":2,"highest":20},{"name":"Alice","score":4,"highest":40},{"name":"Charlie","score":8,"highest":80},{"name":"Bob","score":16,"highest":160}],"index":"name","aggregateFunctions":[{"field":"score","aggregators":["sum"]}]}'
```

Answer (HTTP 200):

```json
{
  "result": [
    {
      "Name": "Alice",
      "Sum of score": 5
    },
    {
      "Name": "Bob",
      "Sum of score": 18
    },
    {
      "Name": "Charlie",
      "Sum of score": 8
    },
    {
      "Name": "Grand Total",
      "Sum of score": 31
    }
  ]
}
```
