where

where keeps the rows for which a condition is true and drops the rest. It is the operator you will write most often, and usually the first one after the table name.

SigninLogs
| where ResultType != "0"

The condition can use comparisons (==, !=, <, >, <=, >=), string operators such as has or startswith, lists with in, ranges with between, and any function that returns true or false. Join conditions with and and or, and wrap a condition in not() to turn it around. and binds tighter than or, so add parentheses when you mix them.

filter is another name for where; you will rarely see it.

Things to know

  • == compares strings with exact case: "Admin" == "admin" is false. Use =~ when case should not matter (see == vs =~).
  • Several where lines in a row are the same as one where with and. Splitting them up often makes a query easier to read and to change.
  • Filter as early as you can. Every operator after where then works on fewer rows, which is faster on a real workspace with billions of rows. Filtering on time first (where TimeGenerated > ago(1d)) is a good habit.

Examples

1 Sign-ins to the two admin portals from outside the home country
SigninLogs
| where AppDisplayName == "Azure Portal" or AppDisplayName == "Microsoft Entra admin center"
| where Location != "CZ"
| project TimeGenerated, UserPrincipalName, AppDisplayName, Location, IPAddress

Two where lines in a row work like one where joined with and.

2 Failed logons on one server, counted per account
SecurityEvent
| where EventID == 4625 and Computer == "SRV-SQL01.kestrelbay.example"
| summarize Failures = count() by TargetUserName

Event 4625 is a failed Windows logon. All of them on this server come from one service account.

3 Everything except the normal sign-ins
SigninLogs
| where not(ResultType == "0" or ResultType == "50140")
| summarize SignIns = count() by ResultType, ResultDescription

not() takes a whole condition. Here it drops successes (0) and the harmless "stay signed in" prompt (50140).

Practice it