Skip to main content

Aggregation Queries

Aggregation queries compute summary values (averages, totals, extremes) across time-series data points instead of returning individual rows. Use these when you need calculated metrics rather than raw data — for example, the average voltage over the last hour or the total energy produced per machine.

OctoMesh supports two aggregation query types:

  • Aggregation Query — computes aggregated values across all matching data points
  • Grouped Aggregation Query — computes aggregated values grouped by one or more columns (similar to SQL GROUP BY)

Aggregation Types​

TypeDescriptionExample
AVGAverage valueAverage voltage over a time range
MINMinimum valueLowest temperature reading
MAXMaximum valuePeak power consumption
COUNTNumber of data pointsNumber of measurements recorded
SUMSum of valuesTotal energy produced
INTEGRALStep integral of the value over the time window, in value unit × hoursEnergy (Wh) from a power column (W) — see Integral

Aggregation Query​

The aggregation query computes a single aggregated result across all matching data points. Use the transientStreamDataAggregationQuery field.

Basic Usage​

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "voltage", aggregationType: MIN },
{ attributePath: "voltage", aggregationType: MAX }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Response:

{
"data": {
"streamData": {
"transientStreamDataAggregationQuery": {
"totalCount": 1,
"items": [
{
"cells": {
"items": [
{ "attributePath": "Avg_voltage", "value": 230.4 },
{ "attributePath": "Min_voltage", "value": 218.7 },
{ "attributePath": "Max_voltage", "value": 242.1 }
]
}
}
]
}
}
}
}

The result contains a single row with one cell per aggregation column. The attributePath in the response is prefixed with the aggregation type (e.g., Avg_voltage, Min_voltage).

Parameters​

ParameterTypeRequiredDescription
ckIdString!YesThe CK type to query
columnPaths[StreamDataQueryColumnInput!]!YesColumns with aggregation type
argStreamDataArgumentsNoTime range and limit overrides
fieldFilter[FieldFilter]NoField-level comparison filters
rtIds[OctoObjectId]NoScope to specific runtime entity IDs
firstIntNoMaximum number of items to return
afterStringNoPagination cursor

StreamDataQueryColumnInput​

Each column specifies the attribute to aggregate and the aggregation function to apply:

FieldTypeRequiredDescription
attributePathString!YesThe data stream attribute to aggregate
aggregationTypeAggregationType!YesAVG, MIN, MAX, COUNT, SUM or INTEGRAL

With Time Range and Entity Filter​

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "power", aggregationType: SUM }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
rtIds: ["65dc6d24cc529cdc46c84fcc"]
) {
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Counting Data Points​

Use COUNT to determine how many data points exist for a given attribute:

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: COUNT }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
) {
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Grouped Aggregation Query​

A grouped aggregation query computes aggregated values grouped by one or more columns — equivalent to a SQL GROUP BY clause. Use the transientStreamDataGroupedAggregationQuery field.

Basic Usage​

This example computes the average voltage per entity:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "power", aggregationType: MAX }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Response:

{
"data": {
"streamData": {
"transientStreamDataGroupedAggregationQuery": {
"totalCount": 3,
"items": [
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fcc" },
{ "attributePath": "Avg_voltage", "value": 230.4 },
{ "attributePath": "Max_power", "value": 1580.0 }
]
}
},
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fcd" },
{ "attributePath": "Avg_voltage", "value": 228.9 },
{ "attributePath": "Max_power", "value": 1620.5 }
]
}
},
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fce" },
{ "attributePath": "Avg_voltage", "value": 231.2 },
{ "attributePath": "Max_power", "value": 1490.3 }
]
}
}
]
}
}
}
}

Each row in the result represents one group. The grouping column values appear in the cells alongside the aggregated values. The groups come ordered by the grouping columns, ascending, so paging with first / after returns every group exactly once while the data does not change (see Row order and paging guarantee).

Parameters​

ParameterTypeRequiredDescription
ckIdString!YesThe CK type to query
groupByColumnPaths[String!]!YesAttribute paths to group by
columnPaths[StreamDataQueryColumnInput!]!YesColumns with aggregation type
argStreamDataArgumentsNoTime range and limit overrides
fieldFilter[FieldFilter]NoField-level comparison filters
rtIds[OctoObjectId]NoScope to specific runtime entity IDs
firstIntNoMaximum number of items to return
afterStringNoPagination cursor

Grouping by Multiple Columns​

You can group by more than one column. This example groups by both entity and CK type:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId", "ckTypeId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

With Filters​

Filters are applied before aggregation, limiting which data points are included in the calculation:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG }
]
fieldFilter: [
{ attributePath: "voltage", operator: GREATER_THAN, comparisonValue: 0 }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

This computes the average voltage per entity, but only considering data points where the voltage is greater than zero.


Integral: energy from power​

INTEGRAL turns a power reading into an energy figure. It integrates a numeric column over the query window [from, to) and returns the result in value unit × hours: a column in W gives Wh, a column in kW gives kWh. For kWh from a W column divide by 1000 (for example with a KPI value multiplier of 0.001). Summing the raw rows (SUM) is not an energy figure — it depends on how often the device reports.

RuleBehaviour
InterpolationStep (last value carried forward): each value holds until the next row of the same entity or the end of the window. There is no linear interpolation.
Carry-inThe last row before from opens the window, so a value reported at 09:30 still counts from 10:00 on. It is looked up at most 35 days back.
GapsA gap between two rows is filled with the earlier value (step rule); the integral does not detect missing data. A row whose value is empty contributes 0 until the next row with a value.
Empty windowNo row in the window and no carry-in row, or only rows without a value: the result is null, not 0.
Several entitiesWithout grouping the integrals of all entities in scope (rtIds, filters) are summed; group by rtId for one figure per entity.
Time windowfrom and to are required; without them the query fails with a stream-data error.
Column typeOnly numeric columns (Integer, Integer64, Double, or a numeric computed column). A text, boolean, enum or built-in column fails with ASSET1004.
ArchivesRaw (event-based) archives, and rollups that store a TimeWeightedAvg of the column (see Integral from a rollup). Time-range archives are refused. Downsampling queries support INTEGRAL on such rollups only.

The result cell is <attribute>_integral (for example activepower_integral) and the column reports aggregationType: INTEGRAL with value type DOUBLE.

query {
streamData {
transientStreamDataQuery {
aggregation(
archiveRtId: "65a1f0c2e4b0a1b2c3d4e5f6"
columnPaths: [{ attributePath: "ActivePower", aggregationType: INTEGRAL }]
arg: { from: "2026-06-01T00:00:00Z", to: "2026-06-02T00:00:00Z", queryMode: DEFAULT }
) {
items {
columns { attributePath aggregationType attributeValueType }
rows { items { cells { items { attributePath value } } } }
}
}
}
}
}

A persisted query stores the same function as the CK value Integral of System/AggregationTypes (aggregationType: INTEGRAL in the create mutation of System/AggregationSdQuery or System/GroupingAggregationSdQuery) and is executed with a time range through streamDataQuery:

query {
streamData {
streamDataQuery(rtId: "<query rtId>") {
items {
columns { attributePath aggregationType }
rows(arg: { from: "2026-06-01T00:00:00Z", to: "2026-06-02T00:00:00Z", queryMode: DEFAULT }) {
items { cells { items { attributePath value } } }
}
}
}
}
}

Integral from a rollup​

For long windows (a month of 5-s rows) query a rollup instead of the raw archive. A rollup answers INTEGRAL when it stores a TimeWeightedAvg aggregation of the column: each bucket already holds the step integral of its rows (same carry-in and step rule as above), and the query adds them up. The same query on the rollup returns the same figure as on the raw archive, read from a few rows per day instead of thousands. A rollup over another rollup works the same way.

RuleBehaviour
Required aggregationThe rollup needs TimeWeightedAvg on the column. A rollup with only Avg, Sum, Min, Max, … of the column refuses INTEGRAL with a stream-data error that names the missing TimeWeightedAvg: a sample average has no time weighting and cannot give energy.
Window edgesThe rollup reads every bucket that overlaps [from, to), in full. Align from and to to the bucket size (whole hours on an hourly rollup, midnight on a daily one) to get exactly the raw result. On a 5-minute rollup [10:07, 11:00) is answered as [10:05, 11:00). For exact edges query the raw archive.
Empty windowNo bucket in the window: null, not 0.
Current bucketThe bucket that is still open counts with what the rollup has aggregated of it so far.
DownsamplingWorks on such a rollup: each bin is the integral of its buckets, for example one kWh value per day from an hourly rollup over a month. Downsampling on a raw archive refuses INTEGRAL.
Grouping, rtIds, filtersAs on the raw archive.

Existing rollups that store only Avg of a power column (activepower_avg_sum, activepower_avg_count) do not answer INTEGRAL; create a rollup with a TimeWeightedAvg aggregation of the column and backfill it with rewindRollupWatermark.

Import and export from one signed power column​

A meter that reports import as positive and export as negative power needs two figures. Split the sign with two computed columns on the archive and integrate each of them:

Computed columnFormula
ImportPowerActivePower > 0 ? ActivePower : 0
ExportPowerActivePower < 0 ? abs(ActivePower) : 0
Do not use a field filter for this

A field filter such as ActivePower > 0 removes the export rows from the event set. The step rule then carries the last positive value across every export period, so the "import" figure grows while the meter exports. Split the sign in a computed column, never with a filter.


Use Cases​

ScenarioQuery TypeExample
Overall average for a KPI widgetAggregationAverage temperature across all sensors
Per-machine production totalsGrouped AggregationTotal output grouped by rtId
Data quality checkAggregation with COUNTCount of readings in a time range
Comparison dashboardGrouped AggregationMin/max/avg per entity for side-by-side display
Energy from power readingsAggregation with INTEGRALkWh of a day from a power column in kW