Skip to main content
These operations stay available. Asset-centric identifiers on these operations are deprecated. Identify the resource with an instance ID (space and externalId) instead.See Deprecated and retired features for dates, and Data modeling status for CDF projects for how DATA_MODELING_ONLY and HYBRID projects behave while you upgrade.
Combine several time series, constants, and operators to create new synthetic time series. Instead of storing computed data, you define expressions that are evaluated at query time, so you always get up-to-date results. Reference a time series by the space and externalId of its CogniteTimeSeries instance, and surround the values with single or double quotes. For example, to calculate the pressure drop across a filter from its inlet and outlet pressure sensors, use the expression TS{space='my_space', externalId='PT-2101'} - TS{space='my_space', externalId='PT-2102'}. You can also apply functions, for example abs(TS{space='my_space', externalId='FIC-3001.SP'} - TS{space='my_space', externalId='FIC-3001.PV'}) for the deviation from a setpoint, and use aggregates as inputs, for example TS{space='my_space', externalId='PT-2101', aggregate='average', granularity='1h'} - TS{space='my_space', externalId='PT-2102', aggregate='average', granularity='1h'} for the hourly average pressure drop.

Functions

Synthetic time series support these functions:
  • Time series inputs.
  • Mathematical operators +,-,*,/.
  • Grouping with brackets ().
  • Trigonometrics. sin(x), cos(x) and pi().
  • ln(x), pow(base, exponent), sqrt(x), exp(x), abs(x).
  • Variable length functions. max(x1, x2, …), min(…), avg(…).
  • round(x, decimals) (-10<decimals<10).
  • on_error(expression, default), for handling errors like overflow or division by zero.
  • map(expression, [list of strings to map from], [list of values to map to], default).
Functions like avg(x1, x2, ...), min(...), and max(...) compute values across multiple inputs at each point in time. They don’t aggregate a single time series across a time range. To aggregate over time, use the aggregate parameter instead, for example, ts{space='my_space', externalId='TT-1001', aggregate='average', granularity='1h'}.

Convert string and state time series to doubles

Synthetic expressions operate on numbers. To use a string or state time series as an input, wrap it in the map() function, which converts its values to doubles. The last argument is the fallback value for values that aren’t in the list. For a string time series, map the text values. If, for example, a time series records diagnostic messages from a pump controller, you can convert the messages to a severity score with:
"Nominal operation" is mapped to 0, "Vibration warning" to 1, and any other message to 2. For a state time series, map the state labels. For example, to plot a valve position as 0 and 1:
A state time series can only appear inside map(). If a data point holds a state that isn’t in the time series’ current state set, for example after the state set was changed, the expression returns an error even though map() has a fallback value. To return a value instead, wrap the expression in on_error():
Synthetic time series expressions don’t support aggregates on string time series inputs.

Error handling: on_error()

There are three possible errors:
  • TYPE_ERROR: You’re using an invalid type as input. For example, a string time series with the division operator.
  • BAD_DOMAIN: You’re using invalid input ranges. For example, division by zero, or sqrt of a negative number.
  • OVERFLOW: The result is more than 10^100 in absolute value.
Instead of returning a value for these cases, CDF returns an error field with an error message. To avoid these, you can wrap the (sub)expression in the on_error() function, for example on_error(1/TS{space='my_space', externalId='FT-1001'}, 0). This can happen because of interpolation, even if none of the raw data points are zero.

How expressions are evaluated

Output timestamps

CDF returns a data point at every timestamp where:
  • Any input time series has a data point.
  • All input time series are defined, that is, between their first and last data point, inclusive.
For example, if time series A has data points at 15, 30, 45, and 60, and time series B has data points at 30, 40, and 50, A + B has data points at 30, 40, 45, and 50.

Interpolation between data points

When an input time series has no data point at an output timestamp, CDF interpolates its value: linearly for continuous time series, and by carrying the previous value forward for stepwise time series. See Stepwise vs continuous. Unlike regular aggregates, synthetic time series interpolate across gaps of any length. If a time series has data points in 1971 and 2050, CDF defines it for every timestamp between them.

Aggregation

To use an aggregate as an input, add the aggregate and granularity parameters to the time series reference, and optionally alignment. The aggregate must be interpolation, stepinterpolation, or average. Enclose the aggregate and granularity values in quotes.
An aggregate input is constant for the whole granularity interval, except interpolation on continuous time series, which changes within the interval. For how CDF calculates each aggregate, and why to prefer interpolation over stepinterpolation, see Common aggregates.

Granularity

Granularity uses the same format as regular aggregates, for example 120s, 15m, 48h, or 365d. See Granularity. Intervals are half-open: they include the start time and exclude the end time. Synthetic time series limit the granularity size to 120 seconds, 120 minutes, 100,000 hours, or 100,000 days.

Alignment

The alignment parameter sets where the aggregate intervals start. It’s a timestamp in milliseconds, and every interval boundary is a whole number of granularities away from it: intervals are on the form [N*granularity + alignment, (N+1)*granularity + alignment), where N is an integer. By default, alignment=0, so intervals are aligned to Thursday 00:00:00 UTC, 1 January 1970. Use alignment when your intervals don’t start at midnight or on a Thursday. For example, a plant that runs three 8-hour shifts starting at 06:00 UTC can calculate the average flow per shift with an 8-hour granularity aligned to 06:00:
This returns one value per shift: 06:00 to 14:00, 14:00 to 22:00, and 22:00 to 06:00. Similarly, granularity='7d' with alignment=345600000 (Monday, 5 January 1970) returns weekly aggregates that start on Mondays instead of Thursdays.
The alignment must be a multiple of the granularity unit. In the shift example, the alignment must be a whole number of hours because the granularity unit is hours.
To align day or month aggregates to local midnight in a time zone, use the timeZone parameter instead of alignment.

Alignment differences from regular aggregates

Synthetic time series and regular data point retrieval align aggregate intervals differently:
The same data and granularity can produce different time boundaries depending on which endpoint you use.For example, if you query with start=08:15:46 and granularity="6s":
  • Regular retrieval rounds the query start time down to the nearest second, so the first interval starts at 08:15:46.
  • Synthetic time series computes intervals at multiples of 6 seconds since epoch (e.g., ...08:15:42, 08:15:48, 08:15:54...). Intervals before the query start time are filtered out, so the first returned interval starts at 08:15:48.
If you see unexpected timestamps or shifted values, check whether the default epoch alignment is the cause. You can override it with the alignment parameter.

Time zone

The timeZone parameter controls how calendar-based granularities (day, month) are interpreted. Specify it at the query level (not per-expression) using any IANA time zone identifier, such as Europe/Oslo or America/New_York.
With a time zone set, day and month granularities align to local midnight. Without one, CDF uses UTC. For daylight saving time handling and worked examples, see Calendar and time zone.

Unit conversion

If a time series has a unit, you can convert its values to a different unit within the same quantity.
For each time series/aggregate, you may specify either targetUnit or targetUnitSystem, but not both. The chosen target unit must be compatible with the original unit. When querying data points using synthetic time series, the values will no longer retain their unit information. For instance, despite it not being physically accurate, it is possible to add values from a temperature time series to those from a distance time series.

Limits

In a single request, you can ask for:
  • 10 expressions (10 synthetic time series).
  • 10,000 data points, summed over all expressions.
  • 100 input time series referrals, summed over all expressions.
  • 2000 tokens in each expression. Similar to 2000 characters, except that words and numbers are counted as a single character.
If you use time series aggregates as inputs, and you get slow responses or a 503 error code, try again or reduce the limit. This is expected behavior when you have recently updated the data points and CDF needs to recalculate aggregates.
Last modified on November 16, 2026