make_set() / make_list()
make_set() and make_list() are aggregates that collect values into a list (a dynamic array),
one list per group:
make_set(x)keeps each value once, likedistinctinside a group.make_list(x)keeps every value, duplicates included.
SigninLogs
| summarize Countries = make_set(Location) by UserPrincipalName
This gives one row per user, with all the countries they signed in from in one cell, such as
["CZ","DE"]. That is often easier to read than many rows, and it opens up checks on the list itself.
Working with the list
array_length(list)returns the number of items.where array_length(Countries) > 1keeps users seen in more than one country.list[0]reads the first item; wrap it intostring()to use it as text.
Column names
Unnamed, the columns are called set_x and list_x, for example set_Location.
Things to know
- The order of the items in the list is not guaranteed.
- Both functions take an optional second argument, the maximum number of items to keep. Big lists make results hard to read, so collect values from groups you already narrowed down.
- On this site,
make_list()andmake_set()accept strings, whole numbers and booleans. Lists of dates are not supported yet;min()andmax()often answer the same question.
Examples
SigninLogs
| where UserPrincipalName == "jonas.weber@kestrelbay.example"
| summarize Apps = make_set(AppDisplayName), Countries = make_set(Location)SecurityEvent
| where EventID == 4624
| summarize LogonTypes = make_set(LogonTypeName), Logons = count() by ComputerDeviceProcessEvents
| where FileName == "cmd.exe"
| summarize Accounts = make_list(AccountName), Unique = make_set(AccountName) by DeviceName
| extend Runs = array_length(Accounts), People = array_length(Unique)Practice it
- #03Spot impossible travel: two countries in one hourmedium
- #10Complete the query: guesses at accounts that don't existmedium
- #15Successful sign-ins from countries that almost never appearmedium
+ 1 in the full SC-200 set · all exercises