let
let gives a name to something so you can use it later in the same query. Each let statement ends
with a semicolon, and the main query comes after the last one.
let threshold = 20;
let lookback = 1d;
SigninLogs
| where TimeGenerated > ago(lookback)
| summarize Failures = countif(ResultType != "0") by IPAddress
| where Failures > threshold
What you can name
- A value: a number, a string, a date, a time span. Putting thresholds and time windows at the top makes a query easy to tune.
- A tabular expression: a whole sub-query, such as
let failures = SigninLogs | where ResultType != "0";. You then usefailureslike a table: start a query with it,joinit, orunionit.
A let can use the names defined above it. Names are case-sensitive.
Why use it
Detection rules and hunting queries in Microsoft Sentinel are full of let: they name the time window,
the thresholds and the intermediate results. That keeps long queries readable, and it lets you use the
same sub-query twice without copying it.
Things to know
- A named sub-query is not stored: it is run where you use it. Using it twice runs it twice.
- After the last
let, write the query itself: theletstatements only prepare names for it. - On this site, user-defined functions (
let f = (x:long) { ... };) andmaterialize()are not supported yet.
Examples
let since = datetime(2026-06-14);
SigninLogs
| where TimeGenerated >= since
| summarize SignIns = count() by AppDisplayNamelet servers = SecurityEvent | distinct Computer;
servers
| countlet minLogons = 100;
let busyServers = SecurityEvent
| where EventID == 4624
| summarize Logons = count() by Computer
| where Logons > minLogons;
busyServers
| join kind=inner (
SecurityEvent
| where EventID == 4634
| summarize Logoffs = count() by Computer
) on Computer
| project Computer, Logons, LogoffsPractice it
None of the free exercises needs this one yet.
+ 8 in the full SC-200 set · all exercises