# Aggregation Features (Optional)

### Practical Examples

To better understand the functionality and practicality of this tool, let’s delve into some real-world operational scenarios:

**Energy Management:**

* Use cumulative aggregation grouped by days to track energy consumption over time.
* Pre-stage with an average aggregation by hours to identify average energy usage for the period cumulated.

**Occupancy Data:**

* Use count aggregation grouped by weeks to find out the number of visitors per week.
* Pre-stage with maximum aggregation by hours to determine the maximum number of occupants over the week.

**Meteorology Data:**

* Use range aggregation grouped by months to identify monthly temperature fluctuations.
* Pre-stage with average aggregation by days to understand daily temperature trends within those months.

These applications are just a glimpse of what’s achievable with the Multi-Stage Data Aggregation API. Depending on your needs, this tool can be tailored to deliver precise and actionable insights and only limited by your creativity.

### Aggregation parameters

**Aggregation Methods:**

You can select from one of the following aggregation outputs:

* Count
* Sum
* Average
* Maximum
* Minimum
* Range
* Difference
* Cumulative

**Aggregation Groupings:**

The above aggregations can be grouped by the following:

* Minutes
* Hours
* Days
* Weeks
* Months
* Years

#### Single Stage Aggregation Parameters

All aggregations must use a final groupby and aggreagteby stage.

| Parameter   | Valid Values                                      | Sequence               |
| ----------- | ------------------------------------------------- | ---------------------- |
| groupby     | `minute` , `hour`, `day`, `week`, `month`, `year` | groupby -> aggregateby |
| aggregateby | `sum`, `avg`, `max`, `min`, `range`, `diff`       |                        |

#### Multi Stage Aggregation Parameters <a href="#aggregration-parameters" id="aggregration-parameters"></a>

<table><thead><tr><th width="217">Parameter</th><th>Valid Values</th><th>Sequence When Apply</th></tr></thead><tbody><tr><td>pregroup</td><td><code>minute</code> , <code>hour</code>, <code>day</code>, <code>week</code>, <code>month</code></td><td><p>pregroup1 &#x26; preaggregate1 → groupby &#x26; aggregateby</p><p></p></td></tr><tr><td>preaggregate1</td><td><code>sum,</code> <code>avg,</code> <code>max,</code> <code>min,</code> <code>range</code></td><td></td></tr><tr><td>pregroup2</td><td><code>hour</code>, <code>day,</code> <code>week</code>, <code>month</code></td><td><p>pregroup1&#x26;preaggregate1 →</p><p>pregroup2 &#x26; preaggregate2 →</p><p>groupby &#x26; aggregateby</p></td></tr><tr><td>preaggregate2</td><td><code>sum,</code> <code>avg,</code> <code>max,</code> <code>min,</code> <code>range</code></td><td></td></tr><tr><td>pregropregroup3</td><td><code>day</code>, <code>week</code>, <code>month</code></td><td><p>pregroup1 &#x26; preaggregate1→</p><p>pregroup2 &#x26; preaggregate2→</p><p>pregroup3 &#x26; preaggregate3→</p><p>groupby &#x26; aggregateby</p></td></tr><tr><td>preaggregate3</td><td><code>sum, avg, max, min, range</code></td><td></td></tr></tbody></table>

When `Multi-stage Aggregation` parameters Applied, `Aggregation` is the Last stage;

When `Multi-stage Aggregation` parameters Not Applied, `Aggregation` is the Only stage;

For `group` parameter, the time range of Previous Stage must be Shorter. For example, If `groupby` is ‘hour’, `pregroup1` must be ‘minute’ and `pregroup2 & 3` and `preaggregate2 & 3` cannot be applied. Other wise the data won’t be accurate.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.alphax.cloud/http/retrieve-data/conduit-v7/aggregation-features-optional.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
