KQL Cheat Sheet: The Basics
Basic Syntax
- Use the
|(pipe) operator to separate multiple commands. - Use the
letkeyword to create variables. - Use the
wherekeyword to filter results. - Use the
projectkeyword to select specific columns. - Use the
summarizekeyword to group and aggregate data.
Filtering Data
wherekeyword:where ColumnName == "Value"inkeyword:where ColumnName in ("Value1", "Value2")containskeyword:where ColumnName contains "Value"startswithkeyword:where ColumnName startswith "Value"endswithkeyword:where ColumnName endswith "Value"haskeyword:where ColumnName has "Value"
Selecting Columns
- Use the
projectkeyword to select specific columns:| project Column1, Column2, ... - Use the
extendkeyword to add calculated columns:| extend NewColumn = Column1 + Column2
Aggregating Data
summarizekeyword:| summarize Aggregation(Column1), Aggregation(Column2) by Column3countkeyword:| summarize count() by Columnmaxkeyword:| summarize max(Column) by Column2minkeyword:| summarize min(Column) by Column2avgkeyword:| summarize avg(Column) by Column2
Joining Data
joinkeyword:Table1 | join kind=inner Table2 on Column1, Column2joinwithproject:Table1 | join kind=inner Table2 on Column1, Column2 | project Column1, Table2.Column2joinwithsummarize:Table1 | join kind=inner Table2 on Column1, Column2 | summarize Aggregation(Column1), Aggregation(Table2.Column2) by Column3