> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/aggregate.md).

# Aggregate

Aggregate functions perform a calculation on multiple values to return a single result. The following functions can be included in your jobs:

<table><thead><tr><th width="327">Function</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/NQgmZwQPwy5sEj9sDJP9">APPROX_COUNT_DISTINCT</a></td><td>Approximates the number of distinct non-null input values. </td></tr><tr><td><a href="/pages/CGhWGTPbng0w8bVt33j6">APPROX_COUNT_DISTINCT_EACH</a></td><td>Approximates the number of distinct values for each given group.</td></tr><tr><td><a href="/pages/oa5MpIkFno3lDdif9u0w">AVG</a></td><td>Computes the average (arithmetic mean) of all input values.</td></tr><tr><td><a href="/pages/EpbeU2Y2ShIrrJQQTGz8">AVG_EACH</a></td><td>Computes the average (arithmetic mean) of all input values for each given group.</td></tr><tr><td><a href="/pages/po23NL7JUtsUeYhqS8U0">AVG_TIME_SERIES</a></td><td>Gets the average value per time interval. </td></tr><tr><td><a href="/pages/fXK14NprIfPCFgwEoCLU">COLLECT_SET</a></td><td>Collects a set of all values for a given field.</td></tr><tr><td><a href="/pages/wHj5B2p3Iq213htuzPkg">COLLECT_SET_EACH</a></td><td>Collects a set of all values for a field for each given group.</td></tr><tr><td><a href="/pages/LcG82BjvZXYaakGp3DLl">COUNT</a></td><td>Counts the number of non-null input values.</td></tr><tr><td><a href="/pages/VIQJgLpFwlDX5KDBp04y">COUNT(*)</a></td><td>Counts the number of input rows.</td></tr><tr><td><a href="/pages/vaKW6I0QabUfdaqjRmkY">COUNT(DISTINCT ...)</a></td><td>Counts the number of distinct non-null input values.</td></tr><tr><td><a href="/pages/4Vbpyfih4slDCpLipPhT">COUNT_EACH</a></td><td>Counts the number of items for each given group.</td></tr><tr><td><a href="/pages/AP0bStuje50ti5tBdRfx">COUNT_IF</a></td><td>Counts the number of <code>TRUE</code> input values. </td></tr><tr><td><a href="/pages/HAn1Qd2ydvmwDPP5GDsH">DYNAMIC_SESSIONS</a></td><td>Collects an array of session start and end times.</td></tr><tr><td><a href="/pages/cyySLM8nuVxv6R3JgjbX">FIRST</a></td><td>Gets the first input value to arrive for each group.</td></tr><tr><td><a href="/pages/bV515X5eUrNAADopqYA4">FIRST_ARRAY</a></td><td>Gets the first array of values seen in the events within the time window.</td></tr><tr><td><a href="/pages/dzEvTBtzSoXWVdorA4yY">FIRST_EACH</a></td><td>Gets an array of the first values per given group in the time window.</td></tr><tr><td><a href="/pages/W0A3XDp31u42g7ebq2a7">FIRST_TIME_SERIES</a></td><td>Gets the first value per time interval. </td></tr><tr><td><a href="/pages/kEggp7s9xaQapvFOBV1g">LAST</a></td><td>Gets the last input value to arrive for each group.</td></tr><tr><td><a href="/pages/5w6BIBiXOdrOmpEdN9LV">LAST_ARRAY</a></td><td>Gets the last array of values seen in the events within the time window.</td></tr><tr><td><a href="/pages/pGNTje2ltTokVq8gzdj4">LAST_EACH</a></td><td>Gets an array of the last values per group in the time window.</td></tr><tr><td><a href="/pages/uyg5EQzZ7pwJjqNtiHGP">LAST_K</a></td><td>Gets the last <code>k</code> values per group.</td></tr><tr><td><a href="/pages/tqc8ewt2jLut2WgG8AnI">LAST_K_EACH</a></td><td>Gets the last <code>K</code> values per given group.</td></tr><tr><td><a href="/pages/4s5JItzrba6C5rUxSkVD">LAST_TIME_SERIES</a></td><td>Gets the last value per time interval. </td></tr><tr><td><a href="/pages/3ZYarDnbZJiPDaEjdTEO">MAX</a></td><td>Computes the maximum of all input values.</td></tr><tr><td><a href="/pages/XFlFvznFXeyuiupazAee">MAX_BY</a></td><td>Gets the value that corresponds to the maximum value of a different field in the time window.</td></tr><tr><td><a href="/pages/sVrbxS2s8nRyVbeVwQlL">MAX_EACH</a></td><td>Collects the maximum value per given group.</td></tr><tr><td><a href="/pages/tqETJtcKB1OYIF1virsE">MAX_TIME_SERIES</a></td><td>Gets the maximum value per time interval.</td></tr><tr><td><a href="/pages/eKiIjVTwJZnUNCPIMJ3Q">MIN</a></td><td>Computes the minimum of all input values.</td></tr><tr><td><a href="/pages/gbBh6zgkeielPwoJMwBT">MIN_BY</a></td><td>Gets the value that corresponds to the minimum value of a different field in the time window.</td></tr><tr><td><a href="/pages/pflGjqzAv5AnujwSz1MP">MIN_EACH</a></td><td>Collects the minimum value per given group.</td></tr><tr><td><a href="/pages/iVUx7HtHM5CCycU0cOfs">MIN_TIME_SERIES</a></td><td>Gets the minimum value per time interval.</td></tr><tr><td><a href="/pages/j06j6DjmXBLPKjeb7lg8">SESSION_COUNT</a></td><td>Counts the number of sessions.</td></tr><tr><td><a href="/pages/LTvYOy0LZSpIAIddyK1i">STD_DEV</a></td><td>Computes the standard deviation of a set of numbers.</td></tr><tr><td><a href="/pages/5W7iTUcH0RPgoXJBAu4V">STD_DEV_EACH</a></td><td>Computes the standard deviation of a set of numbers per given group.</td></tr><tr><td><a href="/pages/VBo6qmQFiYX8wcA0AOUs">STRING_MAX</a></td><td>Computes the maximum of all input string values.</td></tr><tr><td><a href="/pages/TA6JFkZGV3K77pN06Iu7">STRING_MAX_EACH</a></td><td>Collects the maximum string value per given group.</td></tr><tr><td><a href="/pages/E2UB2nAJUyHyaAXYUJBv">STRING_MIN_EACH</a></td><td>Collects the minimum string value per given group.</td></tr><tr><td><a href="/pages/yGFOwbUkvENojl9H5Ll7">SUM</a></td><td>Computes the sum of all input values.</td></tr><tr><td><a href="/pages/RaqXLXfXIKowtn1UD05j">SUM_EACH</a></td><td>Computes the sum of all input values for each given group.</td></tr><tr><td><a href="/pages/MnnJX1Cc3hShfEWgwaU3">SUM_TIME_SERIES</a></td><td>Gets the sum of all values per time interval. </td></tr><tr><td><a href="/pages/lNmpNur2GMXeXrXqhIM7">WEIGHTED_AVERAGE</a></td><td>The weighted average of a field in the time window. </td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/aggregate.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
