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
MAX - Maximum Value
SUM - Sum of Values
AVG - Average Value
COUNT - Count Elements
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:Example 2: Student grade analysis
Calculate grade statistics for students:Example 3: Sensor data monitoring
Monitor and summarize IoT sensor readings: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