Log Analytics workspaces and KQL basics

KQL queries (Kusto Query Language) are how you read everything Azure Monitor collects, whether that’s heartbeats, performance counters, syslog, Windows events or sign-ins, all of it sitting in a Log Analytics workspace.

KQL reads like a pipeline. You start from a table and then filter, shape and summarize it one step at a time using the pipe character. About ten operators cover most of what an admin does day to day, and those ten are what you’ll learn here.

You’ll practise on a small sign-in table that you create yourself, so every answer below comes out exact, and then you’ll run the same patterns on the real data from Lesson 32.

TimeYou needCostBy the end you can
About 45 minutesThe law-saat workspace from Lesson 32, the portal and the CLINothing extra: queries on data already in the workspaceWrite KQL to filter, summarize, bin and chart data, and read KQL error messages

What it is, in one line

KQL is a read-only query language, and each pipe step filters or reshapes the rows handed over by the step before it.

In Simple Words

Sorting the school’s sign-in register

Think of the register at the school gate, where every row has a time, a door, a name and whether the card worked. If you wanted to know who keeps failing at the door, you’d go one step at a time: keep only the failed rows, count them by name, and sort so the biggest count is on top, with each step working on what the last one left you. A KQL query works the same way, and the pipe sign | means “and then”.

Engineer's View

The ten operators you’ll use most

OperatorWhat it doesExample
whereKeeps rows that matchwhere Result == ‘Failure’
projectPicks and renames columnsproject TimeGenerated, User
extendAdds a calculated columnextend Slow = LatencyMs > 300
summarizeGroups and aggregatessummarize count() by User
bin()Buckets time or numbersby bin(TimeGenerated, 1h)
sort by / topOrders rowstop 5 by LatencyMs desc
takeAny N rows, for a quick looktake 10
renderDraws a chart in the portalrender timechart
letNames a value or querylet since = ago(1d);
joinCombines two tables on a keyjoin kind=inner (Perf) on Computer
  • Strings: == cares about case and =~ doesn’t. has matches whole words and is quick, while contains matches any substring and is slower.
  • Time first: filter on TimeGenerated early and set the time range in the portal. The portal applies its time range for you unless your query sets one of its own.
  • Workspace basics: every data type has its own table (Heartbeat, Perf, Syslog, Event), and you set retention per workspace and per table. Queries are read-only, and you only pay for them on some table plans.

How it works, step by step

This is how KQL runs that query, one step at a time:

SignIns
| where Result == 'Failure'
| summarize Failures = count() by User
| sort by Failures desc
KQL queries pipeline: rows flowing through where, summarize and sort
  1. SignIns hands back all 12 rows.
  2. where keeps the 5 rows whose Result is exactly Failure.
  3. summarize groups those 5 rows by User and counts each group, giving ravi 4 and meena 1.
  4. sort puts the biggest count at the top.
  5. You only see what comes out of the last step, and any column that summarize drops is gone for every step after it.

That last point causes the most common KQL error of all, and you’ll trigger it on purpose in Break It.

KQL queries string operators compared: ==, =~, has and contains

Write your queries in that order: the time filter, then the other filters, then shaping and summarizing. They’re easier to read that way and much faster on big tables.

Hands-on lab: KQL queries on a practice table

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Grab your workspace ID, and save the sample data as a KQL function so that any query can call it by name:

$ws = az monitor log-analytics workspace show --resource-group rg-saat-core --name law-saat --query customerId -o tsv
$t = @'
datatable(TimeGenerated:datetime, Computer:string, User:string, Result:string, LatencyMs:int) [
    datetime(2026-10-20 09:05:00), 'web01', 'asha', 'Success', 120,
    datetime(2026-10-20 09:12:00), 'web01', 'ravi', 'Failure', 340,
    datetime(2026-10-20 09:15:00), 'win01', 'asha', 'Success', 95,
    datetime(2026-10-20 09:40:00), 'web01', 'ravi', 'Failure', 410,
    datetime(2026-10-20 09:58:00), 'web01', 'ravi', 'Failure', 380,
    datetime(2026-10-20 10:02:00), 'win01', 'meena', 'Success', 150,
    datetime(2026-10-20 10:20:00), 'web01', 'asha', 'Success', 110,
    datetime(2026-10-20 10:31:00), 'win01', 'ravi', 'Failure', 520,
    datetime(2026-10-20 10:45:00), 'web01', 'meena', 'Success', 130,
    datetime(2026-10-20 11:03:00), 'win01', 'asha', 'Success', 90,
    datetime(2026-10-20 11:10:00), 'web01', 'ravi', 'Success', 200,
    datetime(2026-10-20 11:30:00), 'win01', 'meena', 'Failure', 610
]
'@
Set-Content -Path C:\azure-lab\signins.kql -Value $t
az monitor log-analytics workspace saved-search create --resource-group rg-saat-core --workspace-name law-saat --name signins --category saatvedha --display-name SignIns --func-alias SignIns --saved-query '@C:\azure-lab\signins.kql' -o none
az monitor log-analytics query --workspace $ws --analytics-query "SignIns | count" --query "[0].Count" -o tsv

You should see this:

12

Now open the portal, go to law-saat and then Logs, and switch to KQL mode. Run each of the queries below. The times here are in UTC, but the portal may show your local time.

KQL queries in Log Analytics with the SignIns function
law-saat Logs in KQL mode with the SignIns function.

1Filter and pick columns

SignIns
| where Result == 'Failure'
| project TimeGenerated, Computer, User, LatencyMs
| sort by TimeGenerated asc

You should see this:

TimeGenerated         Computer  User   LatencyMs
2026-10-20 09:12:00   web01     ravi   340
2026-10-20 09:40:00   web01     ravi   410
2026-10-20 09:58:00   web01     ravi   380
2026-10-20 10:31:00   win01     ravi   520
2026-10-20 11:30:00   win01     meena  610

2Count by user

SignIns
| summarize Attempts = count(), Failures = countif(Result == 'Failure') by User
| sort by Failures desc

You should see this:

User   Attempts  Failures
ravi   5         4
meena  3         1
asha   4         0

ravi failed 4 times out of 5. In a real sign-in log, that’s a pattern you’d want to look into.

3Averages and maximums by server

SignIns
| summarize AvgMs = round(avg(LatencyMs), 1), MaxMs = max(LatencyMs) by Computer

You should see this:

Computer  AvgMs  MaxMs
web01     241.4  410
win01     293    610

4Bucket by hour and chart it

SignIns
| summarize Attempts = count() by bin(TimeGenerated, 1h)
| sort by TimeGenerated asc
| render columnchart

You should see this (as a chart in the portal):

TimeGenerated         Attempts
2026-10-20 09:00:00   5
2026-10-20 10:00:00   4
2026-10-20 11:00:00   3

5The same patterns on real data

These run on what web01 and win01 sent during Lesson 32. Set the time range to the last 7 days:

Heartbeat
| summarize LastSeen = max(TimeGenerated) by Computer

Perf
| where CounterName == '% Processor Time'
| summarize AvgCpu = avg(CounterValue) by bin(TimeGenerated, 5m), Computer
| render timechart

Run them one by one by selecting the lines and clicking Run. You’ll see when each VM last reported in, and its CPU curve during the Lesson 32 lab.

KQL timechart of CPU from Log Analytics
Your CPU curve from the Lesson 32 lab. Your times and values will differ.

6Use let, top and dcount

Here are two more operators you’ll reach for every week. let gives a value a name so you don’t keep repeating it, and top gives you the biggest N rows without sorting the whole table first.

let slow = 300;
SignIns
| where LatencyMs > slow
| top 3 by LatencyMs desc
| project TimeGenerated, Computer, User, LatencyMs

You should see this:

TimeGenerated         Computer  User   LatencyMs
2026-10-20 11:30:00   win01     meena  610
2026-10-20 10:31:00   win01     ravi   520
2026-10-20 09:40:00   web01     ravi   410

Next, count how many different users signed in to each server. dcount() counts distinct values, which is what you need for questions like “how many users”, “how many computers” or “how many IP addresses”.

SignIns
| summarize Users = dcount(User), SignIns = count() by Computer

You should see this:

Computer  Users  SignIns
web01     3      7
win01     3      5

All three users showed up on both servers, but web01 handled more sign-ins. Run the same query on SigninLogs or SecurityEvent in a real workspace and it tells you which servers are shared and which belong to one person or one app.

Last of all, look at how the workspace itself is set up. In the portal, open law-saat and then Tables, where each table shows its plan (Analytics or Basic) and its retention.

In one workspace you can keep Heartbeat for 30 days and security events for a year, so you only pay for long retention where an auditor needs it.

Log Analytics workspace tables with plan and retention
law-saat Tables: each table has its own plan and retention.
KQL queries lab: counts by user and averages by server
Two of the lab queries and their exact results.

✅ Checkpoint: The SignIns function returns 12 rows, and your results for steps 1 to 4 match exactly.

Break It, Then Fix It

One of these returns nothing and the other throws an error, and you’ll make both mistakes in everyday KQL.

1Break it: the filter that finds nothing

SignIns
| where Result == 'failure'
| count

You should see this:

Count
0

Zero, even though there are 5 failures. == is case-sensitive and the data says Failure with a capital F. You’ll find this bug in a lot of queries that “prove” nothing happened.

Fix it: use the operator that ignores case, or match the case exactly:

SignIns
| where Result =~ 'failure'
| count

You should see this:

Count
5

2Break it: the column that disappeared

SignIns
| summarize Attempts = count() by User
| where Result == 'Failure'

You’ll get this error:

'where' operator: Failed to resolve scalar expression named 'Result'

After summarize, only User and Attempts are left, so the where is running on summarized rows that no longer have Result. The error names both the operator and the missing column, and that’s all you need to fix it.

Fix it: do the filtering before you summarize:

SignIns
| where Result == 'Failure'
| summarize Failures = count() by User

You should see this:

User   Failures
ravi   4
meena  1

Keep the SignIns function, because Lesson 34 uses it. There’s nothing else to clean up.

Here’s a habit worth building now. When KQL queries come back empty or throw an error, read them from the top one pipe at a time: run the first line on its own, then add the next step and run it again. Wherever the row count falls to zero, or the error first shows up, that’s the step you need to fix.

It works just as well on a five-line query as on a fifty-line one.

KQL queries errors: case-sensitive match and a column dropped by summarize
A case-sensitive filter that finds nothing, and a column summarize threw away.

✅ Checkpoint: You found 5 failures with =~ and fixed a query that used a column summarize had dropped.

This happened at work

“No failed logins last night”

It was right after a security alert. A support engineer was asked whether anyone had failed to sign in to a jump server overnight, so they ran a query filtering on the account name in lower case, got zero rows back and reported “no failures”.

Two days later the security team turned up 3,000 failed attempts against the same account, stored with a capital letter. By then the incident response had been closed early, and the attacker had carried on trying.

What they changed: the team’s query library now uses =~ and has for names and messages. Any “nothing found” answer has to come with a positive control, meaning the same query run on a time window where you know events exist. And a second person reviews saved queries before they go into a runbook.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
== on mixed-case dataZero rows when data existsUse =~ or the exact case.
Using a column after summarize drops it“Failed to resolve scalar expression”Filter and extend before summarize.
No time filter on big tablesSlow queries, timeoutsFilter TimeGenerated first.
contains everywhereSlow searchesPrefer has for whole words.
Wrong portal time rangeOld events missingCheck the picker or set ago() in the query.
Trusting an empty resultFalse “nothing happened”Test the query on a window with known data.

Interview questions

Click any question to open it. They’re worded the way an interviewer would ask them, and under each one you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. What is KQL?

Why they ask this: To see if you know the basic idea.

How you might answer: It’s Kusto Query Language, a read-only language for querying data in Log Analytics, Azure Data Explorer and other Azure services. A query starts from a table and passes the rows through operators using the pipe character.

2. What does summarize do?

Why they ask this: It’s a core operator.

How you might answer: It groups the rows by the columns you list and works out aggregates like count, avg, max or dcount for each group. Any column that isn’t in the by clause or the aggregates gets dropped.

3. What is the difference between == and =~?

Why they ask this: It’s a small detail that matters a lot in real queries.

How you might answer: == checks equality and cares about case, while =~ ignores case. If you use == on mixed-case data, you can get nothing back and not realise why.

2–5 years experience

4. How would you find the busiest hours for failed sign-ins?

Why they ask this: They want to see bin and summarize.

How you might answer: I’d filter to the failures, then summarize count() by bin(TimeGenerated, 1h), sort by time and render a column chart. If I wanted hour of day across many days, I’d use hourofday(TimeGenerated) instead of bin.

5. A query works in the portal but is slow. How do you speed it up?

Why they ask this: They want to hear good query habits.

How you might answer: Filter on TimeGenerated first, then on indexed string conditions using has instead of contains. Project only the columns you need early on, avoid unbounded joins, and summarize before you join where you can.

6. How do you reuse a query across a team?

Why they ask this: They’re checking you know saved searches and functions.

How you might answer: I’d save it as a function with an alias in the workspace, or put it in a query pack shared across workspaces. Then everyone calls it by name, and a fix only has to happen in one place.

Senior level

7. How do you query across several workspaces?

Why they ask this: They want to see you can work at scale.

How you might answer: You can use the workspace() function with union, or query at resource or resource group scope from the portal. I’d still keep the number of workspaces low so this doesn’t become the normal case.

8. How would you prove to an auditor that no admin signed in outside hours?

Why they ask this: They want to see rigour.

How you might answer: I’d give them a documented query over the whole period, with the time range written into the query, case-insensitive matching, and a positive control that shows the query does find sign-ins we know about. Then I’d export the results and the query text together.

9. What table plans exist in Log Analytics, and how do they affect queries?

Why they ask this: They’re checking you think about cost.

How you might answer: Analytics tables support full KQL and alerts. Basic and Auxiliary tables are cheaper to ingest, but they have query limits and you pay per query. High-volume, low-value logs often end up on the cheaper plans.

Quick quiz

Q1. What does the pipe | mean in KQL?

  1. OR
  2. Pass the rows to the next step
  3. Comment
  4. Join
Show answer

B — Each step works on the output of the one before.

Q2. Which operator groups and counts rows?

  1. where
  2. extend
  3. summarize
  4. take
Show answer

C — summarize aggregates by groups.

Q3. where Result == ‘failure’ returns 0, but failures exist. Why?

  1. Wrong table
  2. == is case-sensitive
  3. Time range
  4. Missing render
Show answer

B — Use =~ or match the case exactly.

Q4. Which buckets time into hours?

  1. bin(TimeGenerated, 1h)
  2. take 1h
  3. sort by 1h
  4. project 1h
Show answer

A — bin groups values into fixed-size buckets.

Q5. “Failed to resolve scalar expression named ‘Result'” after summarize means:

  1. Result was dropped by summarize
  2. The table is empty
  3. The workspace is deleted
  4. You need a join
Show answer

A — Only by-columns and aggregates survive summarize.

Quick recap

You can now read Azure Monitor data as a pipeline and trust what your queries are telling you.

  • KQL flows top to bottom: table, then filters, then shape and summarize.
  • == is case-sensitive; =~ isn’t.
  • summarize keeps only the by-columns and aggregates.
  • Filter on time first for speed.
  • Save shared queries as functions.

Next lesson

Lesson 34: KQL for operations: parse logs and log search alerts → Next, you parse messy log lines with KQL and turn a query into an alert.

Further reading: KQL queries

Want to go deeper into KQL queries? Microsoft’s Kusto Query Language overview and Log Analytics tutorial are good next reads, and the full plan for this course is on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.