Skip to content

count_if

Description

Returns the number of rows that satisfy a given condition, counting only non-null expression values.

  • Useful for measuring subsets of data within groups.
  • Can evaluate a condition alone or in combination with a non-null expression.

Note

count_if is an aggregation function and must be used with a grouping keyword such as groupby.

Syntax

count_if(condition: bool, expression: any?): number

Arguments

NameTypeRequiredDescription
conditionbooleantrueBoolean expression indicating whether the row should be counted
expressionanyfalseOptional expression. If provided, only non-null values are counted

Example

Use case: Count high-duration HTTP requests per operation

Suppose you want to count requests where the duration exceeds 500 ms, grouped by operation name.

Example data

{ "operationName": "scheduledEvent", "duration": 567 },
{ "operationName": "HipsterShop", "duration": 512 },
{ "operationName": "login", "duration": 33 }
{ "operationName": "HipsterShop", "duration": 744 },

Example query

source spans
| groupby $l.operationName aggregate count_if($m.duration > 500) as high_duration_request_count

Example output

operationNamehigh_duration_request_count
scheduledEvent1
HipsterShop2