Skip to content

filter

Input Stack:
condition: TimeSeriesExpr
expr: TimeSeriesExpr
Output Stack:
TimeSeriesExpr
 

Filter time series from a grouped expression based on a condition. The condition must evaluate to signal time series (boolean-like values) that determine which time series from the original expression should be included in the output. This is essential for focusing on specific subsets of data that meet certain criteria.

Parameters

  • expr: The grouped time series expression to filter (typically from :by)
  • condition: Signal time series indicating which series to keep (non-zero = keep, zero = exclude)

How It Works

  1. Evaluation: The condition expression is evaluated for each time series in the input
  2. Signal interpretation: Non-zero values in the condition signal mean "keep this series"
  3. Filtering: Only time series where the condition evaluates to non-zero are included
  4. Output: Returns the filtered subset with their original data

Examples

Suppress all time series (condition always evaluates to 0):

BeforeAfter
name,sps,:eq,
(,nf.cluster,),:by
name,sps,:eq,
(,nf.cluster,),:by,
0,:filter

Manual filtering using statistics (verbose approach) - show only lines with average value between 5k and 20k:

BeforeAfter
name,sps,:eq,
(,nf.cluster,),:by
name,sps,:eq,
(,nf.cluster,),:by,
:dup,
avg,:stat,
5e3,:gt,
:over,
avg,:stat,
20e3,:lt,
:and,
:filter

Simplified filtering using stat helpers (recommended approach) - same filter condition as above:

BeforeAfter
name,sps,:eq,
(,nf.cluster,),:by
name,sps,:eq,
(,nf.cluster,),:by,
:stat-avg,
5e3,:gt,
:stat-avg,
20e3,:lt,
:and,
:filter

Stat Helper Integration

The most common filtering pattern uses summary statistics with helper operators that automatically substitute the input expression:

These helpers eliminate the need to manually duplicate the input expression in filtering conditions.

  • :by - Group data for filtering (often used together)
  • :topk / :bottomk - Alternative selection methods
  • :stat - Base statistics for filtering criteria
  • :and / :or - Combine multiple filtering conditions