Kusto Query Language Cheat Sheet
Master the essential Kusto Query Language (KQL) operators used in Azure Log Analytics, Sentinel, and Application Insights. Copy-paste examples included for each operator.
Filtering
Filter rows based on conditions and patterns
where
Filter rows matching a condition
SecurityEvent
| where EventID == 4625
| where TimeGenerated > ago(24h)has_any
Check if column contains any value from a set
ContainerLogV2
| where LogMessage has_any ("error", "failed", "exception")contains
Case-sensitive substring match
ContainerLogV2
| where LogMessage contains "OutOfMemory"startswith
Match strings starting with a prefix
requests
| where name startswith "/api/"Time Functions
Work with timestamps and time intervals
ago()
Time delta from now (e.g., 1h, 7d, 30m)
ContainerLogV2
| where TimeGenerated > ago(1h)
| summarize count() by PodNamenow()
Current time stamp
SecurityEvent
| where TimeGenerated between (ago(24h) .. now())bin()
Round timestamps to a bucket size
Perf
| where TimeGenerated > ago(7d)
| summarize AvgCpu = avg(CounterValue) by bin(TimeGenerated, 1h), ComputerAggregation
Combine and summarize data across rows
summarize
Group rows and apply aggregate functions
requests
| summarize count(), avg(duration), max(duration) by client_CountryOrRegioncount()
Count rows per group
SecurityEvent
| where EventID == 4625
| summarize FailedLogons = count() by Account, Computeravg(), min(), max()
Numeric aggregations across column values
Perf
| where ObjectName == "Processor"
| summarize AvgCpu = avg(CounterValue), MaxCpu = max(CounterValue) by ComputerShaping Output
Select, create, and rename columns
project
Select specific columns; creates new data
requests
| project TimeGenerated, name, duration, client_IP
| where duration > 5000extend
Add computed or derived columns
requests
| extend DurationInSeconds = duration / 1000
| extend IsSlowRequest = DurationInSeconds > 5project-away
Exclude specific columns from output
requests
| project-away customDimensions, customMeasurementsrename
Rename a column
requests
| rename ResponseTime = durationJoins & Unions
Combine data from multiple tables or sets
join
Combine rows from two tables on a key
requests
| where name == "/api/users"
| join (exceptions) on operation_Id
| project TimeGenerated, name, outerMessageunion
Combine result sets from multiple queries
SecurityEvent
| where EventID == 4625
| union (SigninLogs | where ResultType != "0")
| summarize count() by bin(TimeGenerated, 1h)Ordering & Limiting
Sort and restrict result sets
order by
Sort rows ascending or descending
requests
| summarize count() by name
| order by count_ desctop
Return the first N rows after sorting
requests
| order by duration desc
| top 10 by durationlimit
Return the first N rows
requests
| limit 100Ready to write KQL faster?
Join the waitlist for KQL Remix private beta and transform your intent into production-ready queries instantly.
Join Waitlist →Explore how KQL applies to your role: