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 output

Each 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, CKeep only these columns, in this order. project / project-away / project-rename →
T | project A, New = B * 2Rename or compute columns while picking them.
T | project-away A, BDrop these columns, keep the rest.
T | project-rename NewName = OldNameRename a column, keep all others.
T | extend New = A + BAdd 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 ColEach value of Col once. distinct →
T | distinct A, BEach combination of A and B once.
T | distinct *Remove duplicate rows.

Aggregate with summarize

T | summarize count() by ANumber of rows per value of A (column count_). summarize →
T | summarize N = count(), U = dcount(B) by ASeveral 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 | countNumber of rows (column Count). count / count() / countif() →
T | summarize count() by ARows per group (column count_).
T | summarize countif(X > 5) by ARows per group where the condition holds (column countif_).
T | summarize dcount(B) by ANumber of different B values per A (column dcount_B). dcount() / dcountif() →
T | summarize dcountif(B, X == 1) by AThe same, counting only rows where the condition holds.
T | summarize sum(Bytes) by ATotal 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 AFirst and last time per group.
T | summarize arg_max(TimeGenerated, *) by AThe latest full row per A. arg_max() / arg_min() →
T | summarize arg_min(TimeGenerated, B, C) by AThe earliest row per A, keeping B and C.
T | summarize make_set(B) by AThe different B values per A, as a list (column set_B). make_set() / make_list() →
T | summarize make_list(B) by AAll B values per A, duplicates kept (column list_B).
| where array_length(Set) > 1Keep groups with more than one value.

Sort and limit

T | sort by XLargest X first (the default is descending). sort by / order by →
T | sort by X ascSmallest X first.
T | sort by A asc, B descSeveral keys, each with its own direction.
T | top 10 by XThe 10 rows with the largest X. top →
T | top 10 by X ascThe 10 rows with the smallest X.
T | top 1 by TimeGeneratedThe latest row.
T | take 10Any 10 rows. take / limit →
T | limit 10The same as take 10.

Combine tables

A | join kind=inner (B) on KeyRows of A and B with the same Key. join →
A | join kind=leftouter (B) on KeyEvery row of A, with B's columns where there is a match.
A | join kind=leftanti (B) on KeyRows of A that have no match in B.
A | join kind=inner (B) on $left.X == $right.YKeys with different names.
union A, BAll rows of A and of B. union →
union withsource = Src A, BAdd 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() - TimeGeneratedHow 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, 100msTime 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) / BDivide 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

  1. sort by and top are descending unless you write asc.
  2. == is case-sensitive for strings; =~ is not.
  3. has matches whole terms, contains any substring.
  4. Unnamed aggregates are called count_, dcount_X, avg_X and so on.
  5. join without a kind is innerunique, not inner.

From SQL? See KQL vs SQL.