> For the complete documentation index, see [llms.txt](https://sandyzeng.gitbook.io/kql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandyzeng.gitbook.io/kql/kql-quick-guide/my-favorites/extend.md).

# extend

**extend** allow us to build calculated columns of our query results and append them to the result set. You can also extend custom text as well

### 📲 Example: calculate Intune device free storage percentage, and convert storage from MB to GB

```
IntuneDevices
| where TimeGenerated > ago (30d) 
    and OS == 'Windows'
    and isnotempty(SerialNumber)
    and todatetime(LastContact) > ago(60d) //We need to convert LastContact to date time format
| summarize arg_max(TimeGenerated, *) by SerialNumber
| extend StorageTotalGB = round(todouble(StorageTotal)/1024, 3)
        ,StorageFreeGB = StorageFree /1024
        ,['Free Percentage'] = toreal(StorageFree) / toreal(StorageTotal) * 100
| project-reorder TimeGenerated, DeviceName, StorageTotalGB, StorageFreeGB, ['Free Percentage']
```

<figure><img src="https://3533425259-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fbx8yn20QqNJtsVaH9CY7%2Fuploads%2FdyAp9KMBFoiVKrmK53CT%2Fimage.png?alt=media&amp;token=215cdd47-07c3-4180-b188-476dc60ffed2" alt=""><figcaption></figcaption></figure>

### 📲 Example: Get user sign-in details, extend information from device details

```
SigninLogs
| where TimeGenerated > ago (7d)
| extend OperatingSystem = tostring(DeviceDetail.operatingSystem)
| extend DeviceId = tostring(DeviceDetail.deviceId)
| extend Browser = tostring(DeviceDetail.browser)
| distinct UserPrincipalName, UserDisplayName, OperatingSystem, Browser, DeviceId, AppDisplayName
```

<figure><img src="https://3533425259-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fbx8yn20QqNJtsVaH9CY7%2Fuploads%2FRceM4qVc6mmhC0sXrdsT%2Fimage.png?alt=media&amp;token=e64618a2-c22d-4eb0-98fe-e8dba964375b" alt=""><figcaption></figcaption></figure>
