Learn Kusto (KQL)
The query language of Microsoft Sentinel, Defender XDR and Azure Data Explorer. One page per operator or function, each with examples you can run.
Start with where, project, summarize · From SQL: KQL vs SQL · On one page: cheat sheet
Filter rows
| where | Keep only the rows that match a condition |
|---|---|
| == vs =~ | Compare strings with exact case (==) or ignoring case (=~) |
| in / !in / in~ | Check whether a value is one of a list of values |
| between | Check whether a number or time is inside a range |
| isempty / isnotempty / isnull | Find missing values: empty strings and nulls |
Choose and shape columns
| project / project-away / project-rename | Pick, rename, compute or drop columns |
|---|---|
| extend | Add a computed column and keep all the others |
| distinct | List the unique values or combinations of columns |
Aggregate with summarize
| summarize | Group rows and count, sum or average them |
|---|---|
| count / count() / countif() | Count rows, in total, per group, or only those that match |
| dcount() / dcountif() | Count how many different values there are |
| sum() / avg() / min() / max() | Totals, averages, smallest and largest values per group |
| arg_max() / arg_min() | The whole row with the largest or smallest value per group |
| make_set() / make_list() | Collect the values of a group into one list |
Sort and limit
| sort by / order by | Order rows; descending unless you say asc |
|---|---|
| top | The first N rows by a column, descending by default |
| take / limit | Return some rows, with no order guaranteed |
Combine tables
| join | Combine rows from two tables that share a key |
|---|---|
| union | Stack the rows of several tables into one result |
| let | Give a name to a value or a sub-query, then reuse it |
Strings and text
| has vs contains | Whole-term match (has) versus any substring (contains) |
|---|---|
| startswith / endswith | Check the beginning or the end of a string |
| matches regex | Match a string against a regular expression |
| extract() | Pull part of a string out with a regular expression |
| split() / array_length() | Cut a string into a list at a separator |
| strcat() / tolower() / toupper() | Join strings together and change their case |
Dates and times
| ago() / now() | Times relative to the current moment |
|---|---|
| datetime and timespan | Date literals, time spans, date math and datetime_part() |
| bin() / floor() | Round times or numbers down to an interval, for grouping |
Logic and conversion
| iff() / iif() | Choose between two values based on a condition |
|---|---|
| case() | Pick a value from several conditions, with a default |
| tostring() / toint() / todouble() | Convert values between strings and numbers |
Dynamic (JSON) data
| dynamic columns and parse_json() | Read properties and list items from JSON columns |
|---|
Not supported yet: mv-expand, make-series, parse and more. The editor says so when you use them.