Complete KQL (Kusto Query Language) Keywords and Operators
KQL stands for Kusto Query Language. Kustoβs official name is
Azure Data Explorer or ADE. The short way to write ADE is ADX.
It is used in:
- Azure Data Explorer
- Azure Monitor
- Log Analytics
- Application Insights
- Microsoft Sentinel
- Microsoft Fabric (Real-Time Intelligence)
KQL is case-sensitive for everything - table names, table column names, operators, functions, and so on. Keywords can be used as identifiers by enclosing them in brackets and quotes ([' and '] or [" and "]). For example, ['where'].
KQL has several categories of language elements:
- Query operators β
where, project, summarize, extend.
- Logical operators β
and, or, not.
- Comparison operators β
==, !=, contains, in.
- Scalar functions β
iff(), ago(), case(), now().
- Aggregation functions β
count(), sum(), avg().
- Management commands β
.create, .show, .alter.
1. Tabular Query Operators
A. Filtering and Searching
| Operator | Purpose | Example |
| where | Filters rows based on a condition | | where Age > 20 |
| filter | Alias for filtering | | filter Age > 20 |
| search | Searches across columns or tables | search "Azure" |
| find | Searches across specified tables | find in (Table1) "Azure" |
| take | Returns a specified number of rows | | take 10 |
| limit | Alias for take | | limit 10 |
| sample | Returns a random sample | | sample 100 |
| getschema | Returns the schema of the input | | getschema |
B. Selecting and Modifying Columns
| Operator | Purpose | Example |
| project | Selects specific columns | | project Name, Age |
| project-away | Removes specified columns | | project-away Password |
| project-keep | Keeps specified columns | | project-keep Name, Age |
| project-rename | Renames columns | | project-rename UserName = Name |
| project-reorder | Changes column order | | project-reorder Age, Name |
| extend | Creates calculated columns | | extend Total = Price * Quantity |
| evaluate | Invokes a plugin or query extension | | evaluate bag_unpack(Data) |
| serialize | Marks rows as serialized | | serialize |
C. Sorting and Ranking
| Operator | Purpose | Example |
| sort | Sorts rows | | sort by Age asc |
| order | Alias for sorting | | order by Age desc |
| top | Returns top N rows | | top 10 by Score desc |
| top-hitters | Returns most frequent values using an approximate algorithm | | top-hitters 10 of UserId |
| top-nested | Returns top values in hierarchical groups | | top-nested 3 of Category by count() |
| partition | Executes a subquery for each partition | | partition by Region (...) |
D. Grouping and Aggregation
| Operator | Purpose | Example |
| summarize | Groups and aggregates records | | summarize count() by Country |
| count | Counts rows | | count |
| distinct | Returns unique values | | distinct Country |
| make-series | Creates time-series data | | make-series count() on Timestamp |
| scan | Performs stateful row-by-row calculations | | scan declare (...) with (...) |
E. Joining and Combining Tables
| Operator | Purpose | Example |
| join | Combines two tables based on matching columns | T1 | join kind=inner T2 on UserId |
| lookup | Enriches a table using a lookup table | T1 | lookup T2 on UserId |
| union | Combines rows from multiple tables | union Table1, Table2 |
| as | Assigns a name to a tabular expression | T1 | as MyTable |
F. Expanding and Restructuring Data
| Operator | Purpose | Example |
| mv-expand | Expands arrays into multiple rows | | mv-expand Items |
| mv-apply | Applies a subquery to array elements | | mv-apply Items on (...) |
| parse | Extracts values using a parsing pattern | | parse Message with * "ID=" Id |
| parse-where | Parses and retains successfully matched rows | | parse-where Message with ... |
| reduce | Combines similar string values into patterns | | reduce by Message |
G. Set Operations
| Operator | Purpose |
| union | Combines records from multiple datasets |
| intersect | Returns common elements |
| except | Returns elements present in one set but not another |
H. Other Useful Operators
| Operator | Purpose |
| print | Creates a table from scalar expressions |
| datatable | Creates an inline table with specified columns and values |
| range | Generates a sequence of values |
| externaldata | Reads data from an external source |
| invoke | Invokes a function on tabular input |
| fork | Creates multiple branches from the same input |
| consume | Consumes input without returning its rows |
2. Comparison Operators
| Operator | Meaning | Example |
| == | Equal to | Age == 25 |
| != | Not equal to | Age != 25 |
| <> | Not equal to | Age <> 25 |
| > | Greater than | Age > 25 |
| < | Less than | Age < 25 |
| >= | Greater than or equal | Age >= 25 |
| <= | Less than or equal | Age <= 25 |
| =~ | Case-insensitive equality | Name =~ "john" |
| !~ | Case-insensitive inequality | Name !~ "john" |
| in | Matches any value in a list | Status in ("Active", "Pending") |
| !in | Does not match values in a list | Status !in ("Failed", "Error") |
| in~ | Case-insensitive membership | Name in~ ("john", "peter") |
| !in~ | Case-insensitive exclusion | Name !in~ ("john", "peter") |
| between | Checks an inclusive range | Age between (20 .. 30) |
| !between | Checks outside a range | Age !between (20 .. 30) |
| contains | Contains a substring, case-insensitive | Name contains "john" |
| !contains | Does not contain a substring | Name !contains "john" |
| contains_cs | Case-sensitive substring search | Name contains_cs "John" |
| has | Contains a complete term | Message has "error" |
| !has | Does not contain a complete term | Message !has "error" |
| has_cs | Case-sensitive term matching | Message has_cs "Error" |
| startswith | Starts with text | Name startswith "A" |
| !startswith | Does not start with text | Name !startswith "A" |
| startswith_cs | Case-sensitive starts with | Name startswith_cs "A" |
| endswith | Ends with text | Name endswith ".NET" |
| !endswith | Does not end with text | Name !endswith ".NET" |
| endswith_cs | Case-sensitive ends with | Name endswith_cs ".NET" |
| matches regex | Matches a regular expression | Name matches regex @"^[A-Z]" |
| has_any | Contains any specified term | Message has_any ("error", "failed") |
| has_all | Contains all specified terms | Message has_all ("error", "timeout") |
| contains_any | Contains any specified substring | Message contains_any ("err", "fail") |
Difference Between contains and has
// Finds the substring "err"
Logs
| where Message contains "err"
// Finds the complete term "error"
Logs
| where Message has "error"
Important: has is generally more efficient when searching for complete terms because it can use the term index.
3. Logical Operators
| Operator | Meaning | Example |
| and | Both conditions must be true | Age > 18 and Age < 60 |
| or | At least one condition must be true | Status == "Active" or Status == "Pending" |
| not | Negates a condition | not(Status == "Failed") |
| ! | Logical NOT | !IsActive |
Example based on SSR:
TableName
| where DeploymentMode !contains "Halt"
and DeploymentMode !contains "SkipSDP"
Both conditions must be satisfied.
4. Arithmetic Operators
| Operator | Meaning | Example |
| + | Addition | Price + Tax |
| - | Subtraction | Price - Discount |
| * | Multiplication | Price * Quantity |
| / | Division | Total / Count |
| % | Modulus (remainder) | Number % 2 |
Example:
Products
| extend TotalPrice = Price * Quantity
| extend FinalPrice = TotalPrice - Discount
5. Assignment and Column Definition Symbols
| Symbol | Purpose | Example |
| = | Assigns a value or defines a calculated column | extend Total = 100 |
| == | Compares two values | Age == 25 |
| : | Separates column names and data types in schemas | Name:string |
| , | Separates expressions or columns | project Name, Age |
| ; | Separates query statements | let x = 10; print x |
| | | Passes output to the next operator | Table | where Age > 20 |
| () | Groups expressions or supplies function arguments | ago(5d) |
| [] | Accesses dynamic properties or array elements | Data["Name"] |
| {} | Defines function bodies and query blocks | Function body |
| .. | Defines a range | between (1 .. 10) |
| * | Wildcard in supported contexts | project * |
6. Conditional and Control-Flow Functions
| Function | Purpose | Example |
| iff() | Returns a value based on a condition | iff(Age > 18, "Adult", "Minor") |
| iif() | Alternative name for conditional evaluation | iif(Age > 18, "Adult", "Minor") |
| case() | Evaluates multiple conditions | case(Age > 60, "Senior", Age > 18, "Adult", "Other") |
| coalesce() | Returns the first non-null value | coalesce(Value1, Value2, 0) |
| isnull() | Checks whether a value is null | isnull(Name) |
| isnotnull() | Checks whether a value is not null | isnotnull(Name) |
| isempty() | Checks whether a string is empty | isempty(Name) |
| isnotempty() | Checks whether a string is not empty | isnotempty(Name) |
| isblank() | Checks whether a string is empty or whitespace | isblank(Name) |
| isnotblank() | Checks whether a string is not empty or whitespace | isnotblank(Name) |
| toscalar() | Converts a one-value tabular result into a scalar | toscalar(T | count) |
| typeof() | Returns the type of an expression | typeof(123) |
7. String Functions
| Function | Purpose | Example |
| strcat() | Concatenates strings | strcat("Hello", " World") |
| strcat_delim() | Joins strings with a delimiter | strcat_delim("-", A, B) |
| strlen() | Returns string length | strlen(Name) |
| substring() | Extracts part of a string | substring(Name, 0, 5) |
| tolower() | Converts to lowercase | tolower(Name) |
| toupper() | Converts to uppercase | toupper(Name) |
| trim() | Removes specified characters at both ends | trim(" ", Name) |
| replace_string() | Replaces a substring | replace_string(Text, "old", "new") |
| replace_regex() | Replaces text using regex | replace_regex(Text, @"\d+", "") |
| split() | Splits a string into an array | split(Name, ",") |
| extract() | Extracts text using regex | extract(@"ID=(\d+)", 1, Text) |
| extract_all() | Extracts all regex matches | extract_all(@"[0-9]+", Text) |
| parse_json() | Parses JSON text | parse_json(JsonText) |
| parse_url() | Parses a URL | parse_url(Url) |
| indexof() | Finds the position of a substring | indexof(Name, "abc") |
| reverse() | Reverses a string | reverse(Name) |
| translate() | Replaces individual characters | translate("abc", "ab", "xy") |
| url_encode() | URL-encodes a string | url_encode(Name) |
| url_decode() | Decodes a URL-encoded string | url_decode(Name) |
8. Date and Time Functions
| Function | Purpose | Example |
| now() | Current UTC date and time | now() |
| ago() | Date/time in the past | ago(30d) |
| datetime() | Creates a datetime value | datetime(2026-11-16) |
| datetime_add() | Adds a time interval | datetime_add("day", 5, Date) |
| datetime_diff() | Calculates difference between dates | datetime_diff("day", End, Start) |
| datetime_part() | Extracts a date/time component | datetime_part("year", Date) |
| dayofmonth() | Gets day of month | dayofmonth(Date) |
| dayofweek() | Gets day of week | dayofweek(Date) |
| dayofyear() | Gets day of year | dayofyear(Date) |
| getyear() | Gets year | getyear(Date) |
| getmonth() | Gets month | getmonth(Date) |
| hourofday() | Gets hour | hourofday(Date) |
| startofday() | Beginning of day | startofday(now()) |
| endofday() | End of day | endofday(now()) |
| startofweek() | Beginning of week | startofweek(now()) |
| endofweek() | End of week | endofweek(now()) |
| startofmonth() | Beginning of month | startofmonth(now()) |
| endofmonth() | End of month | endofmonth(now()) |
| startofyear() | Beginning of year | startofyear(now()) |
| endofyear() | End of year | endofyear(now()) |
| format_datetime() | Formats datetime as text | format_datetime(now(), "yyyy-MM-dd") |
| todatetime() | Converts value to datetime | todatetime(DateText) |
| totimespan() | Converts value to timespan | totimespan("5.00:00:00") |
| unixtime_seconds_todatetime() | Converts Unix seconds to datetime | unixtime_seconds_todatetime(UnixTime) |
| datetime_utc_to_local() | Converts UTC to local time | datetime_utc_to_local(Date, "India Standard Time") |
Example based on SSR:
TableName
| where ValidFrom > ago(30d)
| extend DaysElapsed = datetime_diff("day", now(), ValidFrom)
| where DaysElapsed > 9
9. Aggregation Functions
| Function | Purpose | Example |
| count() | Counts records | summarize count() |
| countif() | Counts records matching a condition | summarize countif(Age > 18) |
| sum() | Calculates total | summarize sum(Amount) |
| sumif() | Calculates conditional total | summarize sumif(Amount, Status == "Success") |
| avg() | Calculates average | summarize avg(Price) |
| min() | Finds minimum | summarize min(Price) |
| max() | Finds maximum | summarize max(Price) |
| dcount() | Estimates distinct count | summarize dcount(UserId) |
| dcountif() | Estimates conditional distinct count | summarize dcountif(UserId, Active) |
| make_set() | Creates an array of distinct values | summarize make_set(Name) |
| make_list() | Creates an array of values | summarize make_list(Name) |
| make_bag() | Creates a property bag | summarize make_bag(pack("id", Id)) |
| percentile() | Calculates a percentile | summarize percentile(Duration, 95) |
| percentiles() | Calculates multiple percentiles | summarize percentiles(Duration, 50, 95) |
| stdev() | Calculates standard deviation | summarize stdev(Price) |
| variance() | Calculates variance | summarize variance(Price) |
| arg_max() | Returns the row with maximum value | summarize arg_max(Timestamp, *) by UserId |
| arg_min() | Returns the row with minimum value | summarize arg_min(Timestamp, *) by UserId |
| any() | Returns an arbitrary value | summarize any(Name) |
| take_any() | Returns arbitrary records | summarize take_any(*) by UserId |
| count_distinct() | Counts distinct values exactly, where supported | summarize count_distinct(UserId) |
Example:
Orders
| summarize
TotalOrders = count(),
TotalAmount = sum(Amount),
AverageAmount = avg(Amount),
MaximumAmount = max(Amount)
by CustomerId
10. Data Conversion Functions
| Function | Converts Value Into |
| tostring() | String |
| toint() | Integer |
| tolong() | Long integer |
| toreal() | Real number |
| todouble() | Double |
| todecimal() | Decimal |
| tobool() | Boolean |
| todatetime() | Date/time |
| totimespan() | Time interval |
| toguid() | GUID |
| parse_json() | Dynamic JSON object |
| dynamic() | Dynamic value |
Example:
TableName
| extend AgeNumber = toint(AgeText)
| extend IsActiveBoolean = tobool(Status)
11. Dynamic Data and JSON Functions
| Function | Purpose |
| parse_json() | Parses JSON |
| parse_xml() | Parses XML |
| pack() | Creates a property bag |
| pack_array() | Creates an array |
| bag_pack() | Creates a property bag |
| bag_keys() | Returns property names |
| bag_has_key() | Checks whether a property exists |
| bag_remove_keys() | Removes specified properties |
| bag_set_key() | Sets a property value |
| bag_unpack() | Expands property bag fields into columns |
| array_length() | Gets array length |
| array_concat() | Combines arrays |
| array_slice() | Extracts an array section |
| array_sort_asc() | Sorts an array ascending |
| array_sort_desc() | Sorts an array descending |
| set_union() | Combines distinct set elements |
| set_difference() | Finds elements in one set but not another |
| set_intersect() | Finds common elements |
| zip() | Combines arrays element by element |
Example:
TableName
| extend JsonData = parse_json(JsonColumn)
| extend UserName = tostring(JsonData.name)
| extend UserAge = toint(JsonData.age)
| project UserName, UserAge
12. Mathematical Functions
| Function | Purpose |
| abs() | Absolute value |
| round() | Rounds a number |
| ceiling() | Rounds up |
| floor() | Rounds down |
| sqrt() | Square root |
| pow() | Power |
| log() | Natural logarithm |
| log10() | Base-10 logarithm |
| log2() | Base-2 logarithm |
| exp() | Exponential |
| exp2() | Power of 2 |
| exp10() | Power of 10 |
| sin() | Sine |
| cos() | Cosine |
| tan() | Tangent |
| asin() | Inverse sine |
| acos() | Inverse cosine |
| atan() | Inverse tangent |
| pi() | Returns Ο |
| sign() | Returns sign of number |
| bin() | Rounds values down to a bin boundary |
| bin_at() | Bins values using specified alignment |
Example:
TableName
| extend RoundedPrice = round(Price, 2)
| extend AbsoluteValue = abs(Amount)
13. Query Statements and Declarations
| Keyword | Purpose | Example |
| let | Defines a variable or reusable expression | let x = 10; |
| set | Sets a query option | set query_take_max_records = 1000; |
| declare | Declares parameters in supported contexts | declare query_parameters(p:string); |
| query_parameters | Declares query parameters | declare query_parameters(id:string); |
Example: let
let MinimumAge = 18;
Users
| where Age >= MinimumAge
Example: let with datetime
let StartDate = ago(30d);
Orders
| where CreatedDate > StartDate
Example: Query Parameters
declare query_parameters(UserId:string);
Users
| where Id == UserId
14. Management Commands
Management commands generally begin with a dot (.). They are used to create, modify, inspect and manage Kusto objects.
A. Create Commands
| Command | Purpose |
| .create | Creates an object |
| .create-or-alter | Creates or modifies an object |
| .create-merge | Creates or merges an object |
| .create-or-replace | Creates or replaces an object |
B. Alter Commands
| Command | Purpose |
| .alter | Modifies an existing object |
| .alter-merge | Merges changes into an existing object |
| .alter-async | Performs an asynchronous alteration, where supported |
C. Show Commands
| Command | Purpose |
| .show | Displays metadata or information |
| .show tables | Lists tables |
| .show databases | Lists databases |
| .show functions | Lists stored functions |
| .show function | Displays a specific function |
| .show schema | Displays schema information |
| .show commands | Displays management command history |
| .show queries | Displays query history |
| .show diagnostics | Displays diagnostic information, where supported |
D. Drop and Delete Commands
| Command | Purpose |
| .drop | Removes an object |
| .drop table | Removes a table |
| .drop function | Removes a function |
| .drop database | Removes a database |
| .delete | Deletes records using supported management operations |
E. Ingestion and Data Management Commands
| Command | Purpose |
| .ingest | Ingests data |
| .set | Creates or sets a table from query results |
| .set-or-replace | Creates or replaces table data |
| .set-or-append | Creates a table or appends data |
| .append | Appends data to a table |
| .move | Moves supported data or metadata |
| .rename | Renames supported objects |
Important: Not every management command is supported in every KQL environment. Azure Monitor Logs, Microsoft Sentinel and Azure Data Explorer have different command capabilities. Management commands can modify data or metadata, so use them carefully.
Example: Create or Alter Function
.create-or-alter function
with (
docstring = "SSRProblemDetection",
skipvalidation = "true"
)
SSRProblemDetection()
{
// Function body
}
This command creates the function if it does not exist, or updates it if it already exists.
15. Frequently Used KQL Keywords β Quick Reference
| Priority | Keyword | Purpose |
| 1 | where | Filter records |
| 2 | project | Select columns |
| 3 | extend | Create calculated columns |
| 4 | summarize | Group and aggregate |
| 5 | join | Combine tables |
| 6 | union | Combine datasets |
| 7 | distinct | Get unique records |
| 8 | sort | Sort records |
| 9 | take | Limit results |
| 10 | count | Count records |
| 11 | contains | Search text |
| 12 | has | Search complete terms |
| 13 | in | Match multiple values |
| 14 | between | Check ranges |
| 15 | iff() | Conditional expression |
| 16 | case() | Multiple conditions |
| 17 | ago() | Calculate past time |
| 18 | now() | Current time |
| 19 | datetime_diff() | Calculate date differences |
| 20 | arg_max() | Get latest record |
| 21 | parse | Extract information |
| 22 | mv-expand | Expand arrays |
| 23 | make_set() | Create unique-value arrays |
| 24 | let | Declare variables |
| 25 | evaluate | Execute query extensions |
16. Official Microsoft KQL Documentation
Recommended Learning Order
For Azure monitoring and SSR troubleshooting, learn these topics in the following order:
- Basic query structure and pipe operator.
- where, project, extend and distinct.
- Comparison and logical operators.
- contains, has, in and regex.
- iff(), case() and coalesce().
- Date and time functions.
- summarize and aggregation functions.
- join and union.
- parse and dynamic JSON operations.
- let statements and reusable functions.
- Management commands.
- Advanced KQL: window functions, partition, scan and performance optimization.
Note: This is a practical reference covering commonly used KQL operators, functions and commands, not an exhaustive list of every built-in KQL function or reserved identifier. Refer to Microsoft Learn for the complete and current language reference.