Skip to main content

Aggregate Functions

HelixQL provides a comprehensive set of aggregate functions for performing statistical operations and summarizing collections of values. These functions operate on arrays or collections to produce single summary values.

Available Functions

MIN - Minimum Value

Returns the minimum value from a collection of numbers.

MAX - Maximum Value

Returns the maximum value from a collection of numbers.

SUM - Sum of Values

Returns the sum of all values in a collection.

AVG - Average Value

Returns the arithmetic mean (average) of all values in a collection.

COUNT - Count Elements

Returns the number of elements in a collection.
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx file exactly.

Example 1: Statistical analysis of sales data

Analyze sales performance using aggregate functions:
Here’s how to run the query using the SDKs or curl

Example 2: Student grade analysis

Calculate grade statistics for students:
Here’s how to run the query using the SDKs or curl

Example 3: Sensor data monitoring

Monitor and summarize IoT sensor readings:
Here’s how to run the query using the SDKs or curl

Common Aggregate Patterns

Combining Aggregates

Aggregate functions are often used together for comprehensive analysis:

Filtered Aggregates

Combine aggregates with filtering for conditional statistics:

Nested Aggregates

Calculate aggregates on aggregate results:
Aggregate functions are particularly useful for data analysis, reporting, and creating dashboards.

Empty Collections

When aggregate functions are applied to empty collections:
  • COUNT returns 0
  • SUM returns 0
  • AVG, MIN, MAX return null or error depending on implementation

Statistical Variance

To calculate variance and standard deviation, combine aggregate functions:

Performance Considerations

Aggregate functions scan entire collections, so consider:
  • Adding appropriate indexes for frequently aggregated fields
  • Using filters before aggregation to reduce data volume
  • Caching aggregate results for frequently accessed statistics

Unary Math Functions

SQRT, ABS, LN, LOG10, EXP, CEIL, FLOOR, ROUND

Arithmetic Functions

ADD, SUB, MUL, DIV, POW, MOD

Conditionals

Filter data before aggregation

Math Overview

Overview of all math functions