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
DeviceProcessEvents
| summarize Devices = dcount(DeviceName) by FileName
| sort by Devices ascPrograms seen on a single device are often worth a closer look.
SigninLogs
| summarize dcount(IPAddress), dcountif(IPAddress, ResultType != "0") by Location
| sort by dcount_IPAddressThe default names are dcount_IPAddress and dcountif_IPAddress.
Practice it
- #01Find the IP behind a password sprayeasy
- #04Size up a password spray from one IPeasy
- #14Find the one-device destination with hundreds of connectionsmedium
+ 1 in the full SC-200 set · all exercises