Part 2: KQL Syntax Fundamentals
Building on the Basics
Core Tabular Operators
1. where - Filtering Rows
AzureActivity
| where TimeGenerated > ago(24h)
| where OperationNameValue contains "write"
| where Level == "Informational"// Equality
| where Level == "Error"
| where Level != "Informational"
// Numeric comparisons
| where CounterValue > 80
| where CounterValue >= 90
| where DurationMs between (100 .. 1000)
// String operations
| where Message contains "error" // Case-insensitive substring
| where Message !contains "warning"
| where Message startswith "ERROR:"
| where Message endswith "failed"
| where Message matches regex "\\d{3}-\\d{3}-\\d{4}" // Regex pattern
// Case-sensitive versions
| where Message contains_cs "Error" // Case-sensitive
| where Message has "error" // Faster, word boundary matching
| where Message has_cs "Error"2. project - Selecting and Computing Columns
3. extend - Adding Columns Without Removing Others
4. summarize - Aggregating Data
5. order (sort) - Sorting Results
6. take (limit) - Limiting Results
7. top - Getting Top N Results
8. distinct - Unique Values
9. sample - Random Sampling
Data Types in KQL
Common Data Types:
Type Conversion:
String Operations I Use Daily
Extraction and Parsing:
String Matching:
String Building:
DateTime Operations
Relative Time:
Date Parts and Formatting:
Time Calculations:
Time Binning:
Practical Query Patterns
Pattern 1: Error Rate Over Time
Pattern 2: Top Talkers
Pattern 3: Resource Health Check
Pattern 4: Performance Trending
Query Performance Tips
1. Filter Early and Aggressively
2. Use Appropriate Operators
3. Limit During Development
4. Project Only Needed Columns
Common Mistakes I Made
Mistake 1: Wrong operator order
Mistake 2: String comparison case sensitivity
Mistake 3: Not handling nulls
Practice Exercises
Exercise 1: Activity Summary
Exercise 2: Performance Analysis
Exercise 3: String Parsing
Key Takeaways
PreviousPart 1: Introduction to KQL and Azure Log AnalyticsNextPart 3: Advanced Query Operators and Functions
Last updated