extend

extend adds one or more columns to every row. The new column is computed from the row’s other columns, and all existing columns stay as they are.

SecurityEvent
| extend IsFailure = EventID == 4625

You can add several columns in one extend, separated by commas. A column added there can be used by the next operator, for example in a where, a summarize ... by, or a later extend.

Naming

  • Always give the column a name: extend Domain = .... Without a name, Kusto invents one (like Column1), which is hard to work with. This site only accepts unnamed columns in one case: extend ExistingColumn, which changes nothing.
  • If the name already exists, the column is replaced with the new value, in the same position. This is a handy way to normalise a value, e.g. extend UserPrincipalName = tolower(UserPrincipalName).

What you can compute

Anything that gives one value per row: arithmetic (Bytes / 1024), string functions (strcat, extract, split), date math (TimeGenerated - ago(1d)), conditions (iff, case) and reads from dynamic columns.

Aggregations such as count() or dcount() do not belong in extend; they need summarize, because they combine many rows into one.

Examples

1 Build an "IP:port" column, then group by it
DeviceNetworkEvents
| where RemotePort == 445
| extend Endpoint = strcat(RemoteIP, ":", tostring(RemotePort))
| summarize Connections = count() by DeviceName, Endpoint
| where Connections >= 6
2 Add the hour of the day to failed sign-ins
SigninLogs
| where ResultType != "0"
| extend HourUtc = datetime_part("hour", TimeGenerated)
| summarize Failures = count() by HourUtc
| sort by HourUtc asc
3 Replace a column with a cleaned-up version
SigninLogs
| extend UserPrincipalName = tolower(UserPrincipalName)
| summarize SignIns = count() by UserPrincipalName
| top 3 by SignIns

Giving the new column the name of an existing one replaces that column.

Practice it

None of the free exercises needs this one yet.