dcount() / dcountif()

dcount(x) counts how many different values x takes in each group. It answers questions like how many accounts did this IP address try? or on how many devices did this file run?

SigninLogs
| summarize Accounts = dcount(UserPrincipalName) by IPAddress

dcountif(x, condition) does the same, but only over the rows where the condition is true.

Column names

Unnamed, they are called dcount_ plus the column name: dcount(IPAddress) becomes dcount_IPAddress, and dcountif(IPAddress, ...) becomes dcountif_IPAddress.

An estimate in Kusto

On a real Kusto cluster, dcount() is an estimate (it uses the HyperLogLog algorithm to stay fast on billions of rows). For small numbers, like the dozens of accounts in a typical investigation, it is exact in practice. For very large counts it can be off by a small percentage. If you need an exact number for a large set, summarize by the column and then count the rows. On this site, dcount() always counts exactly.

dcount() vs distinct

distinct lists the values; dcount() tells you how many there are. To get both, the list and the number, use make_set() together with dcount().

Examples

1 On how many devices does each program run?
DeviceProcessEvents
| summarize Devices = dcount(DeviceName) by FileName
| sort by Devices asc

Programs seen on a single device are often worth a closer look.

2 Distinct IPs per country, all and failing only
SigninLogs
| summarize dcount(IPAddress), dcountif(IPAddress, ResultType != "0") by Location
| sort by dcount_IPAddress

The default names are dcount_IPAddress and dcountif_IPAddress.

Practice it