Skip to content

Commit 45fea0c

Browse files
authored
Merge pull request #284232 from gardnerjr/users/jgardner/dropdownUpdate
update dropdowns to move column info/etc to the top and explain default selections
2 parents bfae9ee + c219944 commit 45fea0c

File tree

1 file changed

+57
-28
lines changed

1 file changed

+57
-28
lines changed

articles/azure-monitor/visualize/workbooks-dropdowns.md

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Use dropdown parameters to simplify complex reporting with prebuilt
44
services: azure-monitor
55
ms.tgt_pltfrm: ibiza
66
ms.topic: conceptual
7-
ms.date: 06/21/2023
7+
ms.date: 08/14/2024
88
---
99

1010
# Workbook dropdown parameters
@@ -13,6 +13,25 @@ By using dropdown parameters, you can collect one or more input values from a kn
1313

1414
The easiest way to specify a dropdown parameter is by providing a static list in the parameter setting. A more interesting way is to get the list dynamically via a KQL query. You can also specify whether it's single or multi-select by using parameter settings. If it's multi-select, you can specify how the result set should be formatted, for example, as delimiter or quotation.
1515

16+
## Dropdown parameter components
17+
When using either static JSON content or getting dynamic values from queries, dropdown parameters allow up to four fields of information, in this specific order:
18+
19+
1. `value` (required): the first column / field in the data is used as the literal value of the parameter. In the case of simple static JSON parameters, it can be as simple as the JSON content `["dev", "test", "prod"]`, which would create a dropdown of three items with those values as both the value and the label in the dropdown. The name of this field doesn't need to be `value`, the dropdown will use the first field in the data no matter the name.
20+
1. `label` (optional): the second column / field in the data is used as the display name/label of the parameter in the dropdown. If not specified, the value is used as the label. The name of this field doesn't need to be `label`, the dropdown will use the second field in the data no matter the name.
21+
1. `selected` (optional): the third column / field in the data is used to specify which value should be selected by default. If not specified, no items are selected by default. The selection behavior is based on the JavaScript "falsy" concept, so values like `0`, `false`, `null`, or empty strings are treated as not selected. The name of this field doesn't need to be `selected`, the dropdown will use the third field in the data no matter the name.
22+
23+
> [!NOTE]
24+
> This only controls *default* selection, once a user has selected values in the dropdown, those user selected values are used. Even if a subsequent query for the parameter runs and returns new default values. To return to the default selection, the use can use the "Default Items" option in the dropdown, which will re-query the default values and apply them.
25+
>
26+
> Default values are only applied if no items have been selected by the user.
27+
>
28+
> If a subsequent query returns items that do *not* include previously selected values, the missing values are removed from the selection. The selected items in the dropdown will become the intersection of the items returned by the query and the items that were previously selected.
29+
30+
1. `group` (optional): unlike the other fields, the grouping column *must* be named `group` and appear after `value`, `label` and `selected`. This field in the data is used to group the items in the dropdown. If not specified, no grouping is used. If default selection isn't needed, the data/query must still return a `selected` field in at least one object/row, even if all the values are `false`.
31+
32+
> [!NOTE]
33+
> Any other fields in the data are ignored by the dropdown parameter. It is suggested to limit the content to just those fields used by the dropdown to avoid complicated queries returning data that is ignored.
34+
1635
## Create a static dropdown parameter
1736

1837
1. Start with an empty workbook in edit mode.
@@ -22,7 +41,9 @@ The easiest way to specify a dropdown parameter is by providing a static list in
2241
1. **Parameter type**: `Drop down`
2342
1. **Required**: `checked`
2443
1. **Allow multiple selections**: `unchecked`
25-
1. **Get data from**: `JSON`
44+
1. **Get data from**: `JSON` or, select `Query` and select the `JSON` data source.
45+
46+
The JSON data source allows the JSON content to reference any existing parameters.
2647
1. In the **JSON Input** text block, insert this JSON snippet:
2748

2849
```json
@@ -56,6 +77,9 @@ If your query result/JSON contains a `group` field, the dropdown list displays g
5677
<!-- convertborder later -->
5778
:::image type="content" source="./media/workbooks-dropdowns/grouped-dropDown.png" lightbox="./media/workbooks-dropdowns/grouped-dropDown.png" alt-text="Screenshot that shows an example of a grouped dropdown list." border="false":::
5879

80+
> [!NOTE]
81+
> When using a `group` field in your query, you must also supply a value for `label` and `selected` fields.
82+
5983
## Create a dynamic dropdown parameter
6084

6185
1. Start with an empty workbook in edit mode.
@@ -80,9 +104,26 @@ If your query result/JSON contains a `group` field, the dropdown list displays g
80104
<!-- convertborder later -->
81105
:::image type="content" source="./media/workbooks-dropdowns/dropdown-dynamic.png" lightbox="./media/workbooks-dropdowns/dropdown-dynamic.png" alt-text="Screenshot that shows the creation of a dynamic dropdown parameter." border="false":::
82106
107+
## Example: Custom labels, selecting the first item by default, and grouping by operation name
108+
The query used in the preceding dynamic dropdown parameter returns a list of values that are rendered in the dropdown list.
109+
If you want a different display name, or to allow the user to select the display name, use the value, label, selection, and group columns.
110+
111+
The following sample shows how to get a list of distinct Application Insights dependencies. The display names are styled with an emoji, the first item is selected by default, and the items are grouped by operation names:
112+
113+
```kusto
114+
dependencies
115+
| summarize by operation_Name, name
116+
| where name !contains ('.')
117+
| order by name asc
118+
| serialize Rank = row_number()
119+
| project value = name, label = strcat('🌐 ', name), selected = iff(Rank == 1, true, false), group = operation_Name
120+
```
121+
<!-- convertborder later -->
122+
:::image type="content" source="./media/workbooks-dropdowns/dropdown-more-options.png" lightbox="./media/workbooks-dropdowns/dropdown-more-options.png" alt-text="Screenshot that shows a dropdown parameter using value, label, selection, and group options." border="false":::
123+
83124
## Reference a dropdown parameter
84125

85-
You can reference dropdown parameters.
126+
You can reference dropdown parameters anywhere that parameters can be used, including replacing the parameter value into queries, visualization settings, Markdown text content, or other places where you can select a parameter as an option.
86127

87128
### In KQL
88129

@@ -104,42 +145,30 @@ You can reference dropdown parameters.
104145
| summarize Requests = count() by bin(timestamp, 1h)
105146
```
106147
107-
1. Run the query to see the results. Optionally, render it as a chart.
148+
1. Select the **Run query** to see the results. Optionally, render it as a chart.
108149
<!-- convertborder later -->
109150
:::image type="content" source="./media/workbooks-dropdowns/dropdown-reference.png" lightbox="./media/workbooks-dropdowns/dropdown-reference.png" alt-text="Screenshot that shows a dropdown parameter referenced in KQL." border="false":::
110151
111-
## Parameter value, label, selection, and group
112-
113-
The query used in the preceding dynamic dropdown parameter returns a list of values that are rendered faithfully in the dropdown list. But what if you wanted a different display name or one of the names to be selected? Dropdown parameters use value, label, selection, and group columns for this functionality.
114-
115-
The following sample shows how to get a list of Application Insights dependencies whose display names are styled with an emoji, has the first one selected, and is grouped by operation names:
116-
117-
```kusto
118-
dependencies
119-
| summarize by operation_Name, name
120-
| where name !contains ('.')
121-
| order by name asc
122-
| serialize Rank = row_number()
123-
| project value = name, label = strcat('🌐 ', name), selected = iff(Rank == 1, true, false), group = operation_Name
124-
```
125-
<!-- convertborder later -->
126-
:::image type="content" source="./media/workbooks-dropdowns/dropdown-more-options.png" lightbox="./media/workbooks-dropdowns/dropdown-more-options.png" alt-text="Screenshot that shows a dropdown parameter using value, label, selection, and group options." border="false":::
127-
128152
## Dropdown parameter options
129153
130154
| Parameter | Description | Example |
131155
| ------------- |:-------------|:-------------|
132156
| `{DependencyName}` | The selected value | GET fabrikamaccount |
157+
| `{DependencyName:value}` | The selected value (same as above) | GET fabrikamaccount |
133158
| `{DependencyName:label}` | The selected label | 🌐 GET fabrikamaccount |
134-
| `{DependencyName:value}` | The selected value | GET fabrikamaccount |
159+
| `{DependencyName:escape}` | The selected value, with any common quote characters replaced when formatted into queries | GET fabrikamaccount |
135160
136161
## Multiple selection
137162
138163
The examples so far explicitly set the parameter to select only one value in the dropdown list. Dropdown parameters also support *multiple selection*. To enable this option, select the **Allow multiple selections** checkbox.
139164
140-
You can specify the format of the result set via the **Delimiter** and **Quote with** settings. The default returns the values as a collection in the form of **a**, **b**, **c**. You can also limit the number of selections.
165+
You can specify the format of the result set via the **Delimiter** and **Quote with** settings. By default, `,` (comma) is used as the delimiter, and `'` (single quote) is used as the quote character. The default returns the values as a collection in the form of `'a', 'b', 'c'` when formatted into the query. You can also limit the maximum number of selections.
166+
167+
When using a multiple select parameter in a query, make sure that the KQL referencing the parameter works with the format of the result. For example:
168+
- a single value parameter doesn't include any quotes when formatted into a query, so make sure to include the quotes in the query itself, for example: `where name == '{parameter}'`.
169+
- quotes are included in the formatted parameter when using a multiple select parameter, so make sure that the query doesn't include quotes. For example, `where name in ({parameter})`.
141170
142-
The KQL referencing the parameter needs to change to work with the format of the result. The most common way to enable it is via the `in` operator.
171+
Note how this example also switched from `name ==` to `name in`. The `==` operator only allows a single value, while the `in` operator allows multiple values.
143172
144173
```kusto
145174
dependencies
@@ -153,7 +182,7 @@ This example shows the multi-select dropdown parameter at work:
153182

154183
## Dropdown special selections
155184

156-
Dropdown parameters also allow you to specify special values that will also appear in the dropdown:
185+
Dropdown parameters also allow you to specify special values that also appear in the dropdown:
157186
* Any one
158187
* Any three
159188
* ...
@@ -163,9 +192,9 @@ Dropdown parameters also allow you to specify special values that will also appe
163192

164193
When these special items are selected, the parameter value is automatically set to the specific number of items, or all values.
165194

166-
### Special casing All
195+
### Special casing All, and allowing an empty selection to be treated as All
167196

168-
When you select the **All** option, an extra field appears, which allows you to specify that a special value will be used for the parameter if the **All** option is selected. This special value is useful for cases where "All" could be a large number of items and could generate a very large query.
197+
When you select **All**, an additional field appears, which allows you to specify a special value for the **All** parameter. This is useful when "All" could be a large number of items and could generate a very large query.
169198

170199
:::image type="content" source="./media/workbooks-dropdowns/dropdown-all.png" alt-text="Screenshot of the New Parameter window in the Azure portal. The All option is selected and the All option and Select All value field are highlighted." lightbox="./media/workbooks-dropdowns/dropdown-all.png":::
171200

@@ -177,7 +206,7 @@ SomeQuery
177206
| where array_length(selection) == 0 or SomeField in (selection)
178207
```
179208

180-
If all items are selected, the value of `Selection` is `[]`, producing an empty array for the `selection` variable in the query. If no values are selected, the value of `Selection` will be an empty string, also resulting in an empty array. If any values are selected, they are formatted inside the dynamic part of the query, causing the array to have those values. You can then test for `array_length` of 0 to have the filter not apply or use the `in` operator to filter on the values in the array.
209+
If all items are selected, the value of `Selection` is `[]`, producing an empty array for the `selection` variable in the query. If no values are selected, the value of `Selection` is formatted as empty string, also resulting in an empty array. If any values are selected, they're formatted inside the dynamic part of the query, causing the array to have those values. You can then test for `array_length` of 0 to have the filter not apply or use the `in` operator to filter on the values in the array.
181210

182211
Other common examples use '*' as the special marker value when a parameter is required, and then test with:
183212

0 commit comments

Comments
 (0)