KQL cheat sheet
Every Kusto (KQL) operator and function this site supports. T is any table.
The shape of a query
SigninLogs // 1. a table
| where TimeGenerated > ago(1d) // 2. filter early
| where ResultType != "0"
| summarize Failures = count() by IPAddress // 3. aggregate
| where Failures > 10
| sort by Failures desc // 4. order (desc is the default)
| project IPAddress, Failures // 5. shape the outputEach line takes the result of the line above. // starts a comment. Strings take single or double quotes; @"C:\path" is a verbatim string.
Filter rows
T | where Col == "x" | Keep rows where Col is exactly "x". where → |
T | where A > 5 and (B == 1 or C != 2) | Combine conditions; use parentheses when you mix and and or. |
T | where not(Col has "test") | Negate a whole condition. |
Col == "Admin" | Equal, same case. == vs =~ → |
Col =~ "admin" | Equal, ignoring case. |
Col != "Admin" | Not equal, same case. |
Col !~ "admin" | Not equal, ignoring case. |
Col in ("a", "b", "c") | Col is one of the values (case matters). in / !in / in~ → |
Col in~ ("a", "b") | The same, ignoring case. |
Col !in (1, 2, 3) | Col is none of the values. |
X between (1 .. 10) | X is from 1 to 10, ends included. between → |
T between (datetime(2026-06-14) .. datetime(2026-06-15)) | A time window. |
X !between (1 .. 10) | X is below 1 or above 10. |
isempty(Col) | True when a string is "" (or a value is null). isempty / isnotempty / isnull → |
isnotempty(Col) | The opposite of isempty. |
isnull(Num) | True when a number, date or time is null. |
Choose and shape columns
T | project A, B, C | Keep only these columns, in this order. project / project-away / project-rename → |
T | project A, New = B * 2 | Rename or compute columns while picking them. |
T | project-away A, B | Drop these columns, keep the rest. |
T | project-rename NewName = OldName | Rename a column, keep all others. |
T | extend New = A + B | Add a column computed from others. extend → |
T | extend A = tolower(A) | Overwrite a column with a new value. |
T | extend X = 1, Y = strcat(A, B) | Several columns at once, separated by commas. |
T | distinct Col | Each value of Col once. distinct → |
T | distinct A, B | Each combination of A and B once. |
T | distinct * | Remove duplicate rows. |
Aggregate with summarize
T | summarize count() by A | Number of rows per value of A (column count_). summarize → |
T | summarize N = count(), U = dcount(B) by A | Several named aggregates per group. |
T | summarize count() by bin(TimeGenerated, 1h) | Rows per hour. |
T | summarize max(X) | No by: one row for the whole table. |
T | count | Number of rows (column Count). count / count() / countif() → |
T | summarize count() by A | Rows per group (column count_). |
T | summarize countif(X > 5) by A | Rows per group where the condition holds (column countif_). |
T | summarize dcount(B) by A | Number of different B values per A (column dcount_B). dcount() / dcountif() → |
T | summarize dcountif(B, X == 1) by A | The same, counting only rows where the condition holds. |
T | summarize sum(Bytes) by A | Total per group (column sum_Bytes). sum() / avg() / min() / max() → |
T | summarize avg(Duration) | Average, always a decimal number (column avg_Duration). |
T | summarize min(TimeGenerated), max(TimeGenerated) by A | First and last time per group. |
T | summarize arg_max(TimeGenerated, *) by A | The latest full row per A. arg_max() / arg_min() → |
T | summarize arg_min(TimeGenerated, B, C) by A | The earliest row per A, keeping B and C. |
T | summarize make_set(B) by A | The different B values per A, as a list (column set_B). make_set() / make_list() → |
T | summarize make_list(B) by A | All B values per A, duplicates kept (column list_B). |
| where array_length(Set) > 1 | Keep groups with more than one value. |
Sort and limit
T | sort by X | Largest X first (the default is descending). sort by / order by → |
T | sort by X asc | Smallest X first. |
T | sort by A asc, B desc | Several keys, each with its own direction. |
T | top 10 by X | The 10 rows with the largest X. top → |
T | top 10 by X asc | The 10 rows with the smallest X. |
T | top 1 by TimeGenerated | The latest row. |
T | take 10 | Any 10 rows. take / limit → |
T | limit 10 | The same as take 10. |
Combine tables
A | join kind=inner (B) on Key | Rows of A and B with the same Key. join → |
A | join kind=leftouter (B) on Key | Every row of A, with B's columns where there is a match. |
A | join kind=leftanti (B) on Key | Rows of A that have no match in B. |
A | join kind=inner (B) on $left.X == $right.Y | Keys with different names. |
union A, B | All rows of A and of B. union → |
union withsource = Src A, B | Add a column with each row's table name. |
A | union (B | where X == 1) | Add rows from a filtered table. |
let threshold = 10; | Name a value; end each let with a semicolon. let → |
let lookback = 7d; | Name a time span. |
let bad = T | where X > 1; | Name a sub-query and use it like a table. |
Strings and text
Col has "admin" | "admin" appears as a whole term (any case). has vs contains → |
Col contains "adm" | "adm" appears anywhere (any case). |
Col has_cs "Admin" | Whole term, exact case. |
Col !has "test" | The term does not appear. |
Col startswith "svc_" | Begins with "svc_" (any case). startswith / endswith → |
Col endswith ".ps1" | Ends with ".ps1" (any case). |
Col endswith_cs ".EXE" | Ends with ".EXE", exact case. |
Col !startswith "10." | Does not begin with "10.". |
Col matches regex @"^\d+$" | Col is made only of digits. matches regex → |
Col matches regex @"(?i)admin" | Pattern anywhere, ignoring case. |
extract(@"(\d+)", 1, Col) | The first run of digits in Col. extract() → |
extract(@"user=(\w+)", 1, Col) | The word after "user=". |
extract(@"\d+", 0, Col) | Group 0 is the whole match. |
split(Col, ",") | A list of the parts between commas. split() / array_length() → |
tostring(split(Col, "@")[0]) | The first part, as a string. |
array_length(split(Col, ".")) | How many parts there are. |
strcat(A, "-", B) | Join values into one string. strcat() / tolower() / toupper() → |
tolower(Col) | The string in lower case. |
toupper(Col) | The string in upper case. |
Dates and times
where TimeGenerated > ago(1d) | The last 24 hours. ago() / now() → |
where TimeGenerated between (ago(7d) .. ago(1d)) | From 7 days ago to 1 day ago. |
extend Age = now() - TimeGenerated | How long ago each event happened (a time span). |
datetime(2026-06-14 08:30) | A date and time (UTC). datetime and timespan → |
1d, 6h, 30m, 10s, 100ms | Time spans. |
TimeGenerated - ago(1h) | datetime minus datetime gives a time span. |
datetime_part("hour", TimeGenerated) | One part of a date, as a number. |
summarize count() by bin(TimeGenerated, 1h) | Rows per hour. bin() / floor() → |
bin(TimeGenerated, 1d) | The start of the day (UTC). |
bin(Bytes, 1000) | Numbers in steps of 1,000. |
Logic and conversion
iff(X > 10, "high", "low") | One of two values per row. iff() / iif() → |
iff(isempty(A), B, A) | Fall back to B when A is empty. |
case(A > 10, "high", A > 5, "medium", "low") | First true condition wins; the last value is the default. case() → |
tostring(42) | "42" tostring() / toint() / todouble() → |
todouble(A) / B | Divide with decimals. |
tolong(DynamicCol.count) | A number out of a dynamic value. |
Dynamic (JSON) data
tostring(Col.city) | A property, as text. dynamic columns and parse_json() → |
tostring(Col.user.displayName) | A nested property. |
tostring(Col[0].id) | A property of the first list item. |
tostring(Col["key name"]) | Bracket notation, for any key. |
Five traps
sort byandtopare descending unless you writeasc.==is case-sensitive for strings;=~is not.hasmatches whole terms,containsany substring.- Unnamed aggregates are called
count_,dcount_X,avg_Xand so on. joinwithout a kind isinnerunique, notinner.
From SQL? See KQL vs SQL.