Home / Search/ Language Reference/ Functions/ Statistical Functions/countif

countif

The countif aggregation function counts events based on a predicate.

Use this function with the summarize, eventstats, and timestats operators.

If you need to count non-null values regardless of truthiness, use the count aggregation function.

Syntax

    countif( Predicate )

Arguments

  • Predicate: An expression used for aggregation calculation. Use any scalar expression that returns a bool value. Wildcards are not supported for field names.

Results

Returns a count of rows for which Predicate evaluates to true.

Examples

Counting storms by state

This example shows the number of storms with damage to crops by state.

dataset=myDataset
| summarize TotalCount=count(),TotalWithDamage=countif(DamageCrops >0) by State

Counting based on string length

This example shows the number of names with more than 4 letters.

dataset=myDataset
| summarize countif(strlen(name) > 4)