distinct
distinct returns one row for each unique combination of the columns you name, and only those
columns.
SigninLogs
| distinct UserPrincipalName, Location
This lists every user together with every country they signed in from. A user seen from two
countries appears twice, once per country. distinct * uses all columns and removes exact duplicate
rows.
distinct, dcount() or summarize?
distinctgives you the values themselves.dcount()gives you how many different values there are, e.g. the number of users per IP address.summarize ... by A, Bgives the same rows asdistinct A, B, and lets you add aggregates such ascount()next to them. So when you also want a count, go straight tosummarize.make_set()puts the distinct values into one list per group.
Things to know
- The rows come back in no particular order. Add
sort byif order matters. - Comparisons are exact:
Adminandadminare two different values. Normalise first if needed:extend Name = tolower(Name) | distinct Name.
Examples
SigninLogs
| distinct ClientAppUsedSecurityEvent
| where EventID == 4624
| distinct Computer, LogonTypeNameEach server appears once per kind of logon it saw.
DeviceProcessEvents
| where FileName == "cmd.exe"
| distinct DeviceName, AccountNamePractice it
None of the free exercises needs this one yet.
+ 2 in the full SC-200 set · all exercises