countif() (aggregation function)

countif() (aggregation function)

Counts the rows in which predicate evaluates to true.

[!INCLUDE data-explorer-agg-function-summarize-note]

Syntax

countif (predicate)

Parameters

NameTypeRequiredDescription
predicatestringThe expression used for aggregation calculation. The value can be any scalar expression with a return type of bool.

Returns

Returns a count of rows in which predicate evaluates to true.

Examples

Count storms by state

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

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

The results table shown includes only the first 10 rows.

StateTotalCountTotalWithDamage
TEXAS470172
KANSAS316670
IOWA2337359
ILLINOIS202235
MISSOURI201678
GEORGIA198317
MINNESOTA188137
WISCONSIN185075
NEBRASKA1766201
NEW YORK17501
.........