> For the complete documentation index, see [llms.txt](https://carpool.gitbook.io/carpool/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://carpool.gitbook.io/carpool/api-reference/instructions/field_statistic_instruction.md).

# FIELD\_STATISTIC\_INSTRUCTION

## Overview

*This method allows you to aggregate instructions through basic statistics and an optional robust filter object. There are many types of filters you can apply and you can find information regarding those in the* [*Filters*](/carpool/api-reference/filters.md) *section of the docs. The endpoint example here shows off one of the many filters.*

{% openapi src="/files/jrV5F799tHmdumrTu8wy" path="/query/solana" method="post" %}
[Carpool\_dev-FIELD\_STATISTIC\_INSTRUCTION-0.1-resolved.json](https://2513171703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE1gzfwcjB542lI2VR9XI%2Fuploads%2Fs2E7kk5WkcsFLk51ns13%2FCarpool_dev-FIELD_STATISTIC_INSTRUCTION-0.1-resolved.json?alt=media\&token=c62a0d0c-0931-4c69-9a14-1fa8473fb8ec)
{% endopenapi %}

## Statistic

The "statistic" field in the post body is based on the following type and can adapt to the kind of query you wish to perform

```typescript
type FieldStatistic = 'avg' | 'sum' | 'std' | 'min' | 'max' | { percentile: number }
```

## Filters

As mentioned above, the api definition here illustrates one of Carpool's many filter types. The filter object is **optional** here, but all queries that accept a filter object in the POST body can make use of **any** of the potential filters. Please see the Instruction Filters section of the documentation to better understand how they are implemented for instruction queries.

{% content-ref url="/pages/uYgjTokygYFjAlLVuwUH" %}
[Instruction Filters](/carpool/api-reference/filters/instruction-filters.md)
{% endcontent-ref %}

## Example - Basic

**Program** - *Candy Machine*

**Description** *- Return the average of the numeric value found at argument data.creators.percentageShare*

#### Javascript

```javascript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "<API_KEY>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "type": "FIELD_STATISTIC_INSTRUCTION",
  "query": {
    "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
    "path": "data.creators.percentageShare",
    "statistic": "avg"
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mainnet.carpool.dev/query/solana", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

#### cURL

```
curl --location 'https://mainnet.carpool.dev/query/solana' \
--header 'x-api-key: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "type": "FIELD_STATISTIC_INSTRUCTION",
    "query": {
        "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
        "path": "data.creators.percentageShare",
        "statistic": "avg"
    }
}'
```

## Example - Advanced

**Program** - *Candy Machine*

**Description** *- Find the minimum numeric value found at argument data.creators.percentageShare. Filter for only initializeV2 instructions within a set time range.*

#### Javascript

```javascript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "<API_KEY>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "type": "FIELD_STATISTIC_INSTRUCTION",
  "query": {
    "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
    "path": "data.creators.percentageShare",
    "statistic": "min",
    "filter": {
      "type": "INSTRUCTION_NAME",
      "instructionName": "initializeV2"
    },
    "timeRange": {
      "before": "2023-07-12T22:53:09+0000",
      "after": "2023-07-11T22:53:09+0000"
    }
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mainnet.carpool.dev/query/solana", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

#### cURL

```
curl --location 'https://mainnet.carpool.dev/query/solana' \
--header 'x-api-key: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "type": "FIELD_STATISTIC_INSTRUCTION",
    "query": {
        "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
        "path": "data.creators.percentageShare",
        "statistic": "min",
        "filter": {
            "type": "INSTRUCTION_NAME",
            "instructionName": "initializeV2"
        },
        "timeRange": {
            "before": "2023-07-12T22:53:09+0000",
            "after": "2023-07-11T22:53:09+0000"
        }
    }
}'
```
