Skip to content

Commit

Permalink
Update dashboard-template-variables.mdx
Browse files Browse the repository at this point in the history
Dividing examples from uniques and keysets
  • Loading branch information
chmartinez committed May 8, 2024
1 parent 0d0ad46 commit 3bf6826
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,30 +315,30 @@ Here's an example of the resulting widget, on the right, with the `country` drop

## Rules for writing a query-type template variable [#query-variable-rules]

As discussed in the [section on defining template variables](#step1), there are three variable types: query, list, and text field. The query-type variable is the most complex to create because you must create a working query that returns values, which are then used to populate the dropdown in the template variable bar at the top of the dashboard.
As discussed in the [section on defining template variables](#step1), there are three variable types: query, list, and text field. The query-type variable is the most complex to create because you must create a working query that returns **a list of values**, which are then used to populate the dropdown in the template variable bar at the top of the dashboard.

<Callout variant="important">
Note that this is a different topic than writing queries that make use of a template variable.
</Callout>

Here are some rules and guidance on creating a query-type variable:
* Queries must use the `uniques` or `keyset` syntax.
* The same syntax and limits of both functions are applicable here. Examples:

```sql
From PageAction select uniques(countryCode) --> this will return up to 1k results
```

```sql
From PageAction select uniques(countryCode, 10000) --> this will return up to 10k results
```
* You can use almost any NRQL query as long as it returns a list of values. For that, you can use either the `uniques` or `keyset` functions:
* with `uniques`:
```sql
From PageAction select uniques(countryCode)
```
```sql
-- you can use the second param to define the maximum number of results to be listed.
From PageAction select uniques(countryCode, 10000) --> this will return up to 10k results
```
Reference docs: [`uniques`](/docs/nrql/nrql-syntax-clauses-functions/#func-uniques)
* with `keyset`
```sql
--- with `keyset`, you'll get a list with all of the attributes from the table you're querying from
From PageAction select keyset() SINCE 1 day ago
```
Reference docs: [`keyset`](/docs/nrql/nrql-syntax-clauses-functions/#keyset)

```sql
From PageView select keyset() SINCE 1 day ago
```
Please, check [`uniques`](/docs/nrql/nrql-syntax-clauses-functions/#func-uniques) and the [`keyset`](/docs/nrql/nrql-syntax-clauses-functions/#keyset) for more info.

* You can use almost any NRQL query as long as the `uniques` and `keyset` components return a list of values.
* Nested variables are not supported: there can't be variables within variables.

## Some examples [#examples]
Expand Down

0 comments on commit 3bf6826

Please sign in to comment.