Skip to content

Commit 06f31f6

Browse files
committed
function article
1 parent 4c57426 commit 06f31f6

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

articles/azure-monitor/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@
690690
href: ../log-analytics/query-language/advanced-query-writing.md?toc=/azure/azure-monitor/toc.json
691691
- name: Charts and diagrams
692692
href: ../log-analytics/query-language/charts.md?toc=/azure/azure-monitor/toc.json
693+
- name: Functions
694+
href: ../log-analytics/query-language/functions.md?toc=/azure/azure-monitor/toc.json
693695
- name: Cheatsheets
694696
items:
695697
- name: SQL

articles/log-analytics/query-language/functions.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Functions Azure Log Analytics | Microsoft Docs
3-
description: This article provides a tutorial for using the Analytics portal to write queries in Log Analytics.
3+
description: This article describes how to use functions to call a query from another query in Log Analytics.
44
services: log-analytics
55
documentationcenter: ''
66
author: bwren
@@ -12,7 +12,7 @@ ms.workload: na
1212
ms.tgt_pltfrm: na
1313
ms.devlang: na
1414
ms.topic: conceptual
15-
ms.date: 08/16/2018
15+
ms.date: 11/15/2018
1616
ms.author: bwren
1717
ms.component: na
1818
---
@@ -25,8 +25,31 @@ ms.component: na
2525
2626
[!INCLUDE [log-analytics-demo-environment](../../../includes/log-analytics-demo-environment.md)]
2727

28-
## Functions
29-
You can save a query with a function alias so it can be referenced by other queries. For example, the following standard query returns all missing security updates reported in the last day:
28+
> [!NOTE]
29+
> Saving a function is possible in Log Analytics queries, but currently not for Application Insights queries.
30+
31+
32+
To use a Log Analytics query with another query you can save it as a function. This allows you to simplify complex queries by breaking them into parts and allows you to reuse common code with multiple queries.
33+
34+
> [!NOTE]
35+
> A function in Log Analytics cannot contain another function.
36+
37+
## Create a function
38+
39+
Create a function in the Azure portal by clicking **Save** and then providing the information in the following table.
40+
41+
| Setting | Description |
42+
|:---|:---|
43+
| Name | Display name for the query in **Query explorer**. |
44+
| Save as | Function |
45+
| Function Alias | Short name to use the function in other queries. May not contain spaces and must be unique. |
46+
| Category | A category to organize saved queries and functions in **Query explorer**. |
47+
48+
## Use a function
49+
Use a function by including its alias in another query. It can be used like any other table.
50+
51+
## Example
52+
The following sample query returns all missing security updates reported in the last day:
3053

3154
```Kusto
3255
Update
@@ -35,18 +58,14 @@ Update
3558
| where UpdateState == "Needed"
3659
```
3760

38-
You can save this query as a function and give it an alias such as _security_updates_last_day_. Then you can use it in another query to search for SQL-related needed security updates:
61+
Save this query as a function with the alias _security_updates_last_day_.
62+
63+
Create another to search for SQL-related needed security updates:
3964

4065
```Kusto
4166
security_updates_last_day | where Title contains "SQL"
4267
```
4368

44-
To save a query as a function, select the **Save** button in the portal and change **Save as** to _Function_. The function alias can contain letters, digits, or underscores but must start with a letter or an underscore.
45-
46-
> [!NOTE]
47-
> Saving a function is possible in Log Analytics queries, but currently not for Application Insights queries.
48-
49-
5069
## Next steps
5170
See other lessons for using the Log Analytics query language:
5271

0 commit comments

Comments
 (0)