Skip to content

Commit

Permalink
Merge pull request #17217 from chmartinez/patch-1
Browse files Browse the repository at this point in the history
Update dashboard-template-variables rules
  • Loading branch information
akristen committed May 8, 2024
2 parents f43c01b + 1289a0f commit f1c0fbc
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ There are three options:
```sql
SELECT uniques(countryCode) FROM PageAction since 2 days ago
```

For rules and tips on writing queries, see [Query-type variables](#query-variable-rules).

* <DoNotTranslate>**List**</DoNotTranslate>: A list of comma-separated values that are used to populate the options in the dropdown menu. For example, you could manually define a list of `country` values using a list like: `ES, US, CA.`
* <DoNotTranslate>**Text field**</DoNotTranslate>: Instead of a dropdown of values to choose from, this allows dashboard users to filter for whatever text they input.
</td>
Expand Down Expand Up @@ -315,25 +317,33 @@ 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. Uniques return up to 10,000 results. Check [`uniques`](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#func-uniques) and the [`keyset`](/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/#keyset). Here's a couple of query examples:

```sql
From PageAction select uniques(countryCode)
```
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.

```sql
From PageView select keyset() SINCE 1 day ago
```

* 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.
With [`uniques`](/docs/nrql/nrql-syntax-clauses-functions/#func-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
```

With [`keyset`](/docs/nrql/nrql-syntax-clauses-functions/#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
```

Keep in mind that nested variables are not supported as there can't be variables within variables.

## Some examples [#examples]

Expand Down

0 comments on commit f1c0fbc

Please sign in to comment.