You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
30
53
31
54
```Kusto
32
55
Update
@@ -35,18 +58,14 @@ Update
35
58
| where UpdateState == "Needed"
36
59
```
37
60
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:
39
64
40
65
```Kusto
41
66
security_updates_last_day | where Title contains "SQL"
42
67
```
43
68
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
-
50
69
## Next steps
51
70
See other lessons for using the Log Analytics query language:
0 commit comments