03 Variables

Use Grafana dashboard variables with ENLYZE data.

What You'll Learn

  • Create dashboard variables for dynamic filtering

  • Build site and machine dropdown selectors

  • Chain variables so machine options depend on selected site

  • Use variables in Infinity queries

  • Create hidden helper variables

Prerequisites

  • Completed Tutorial 4.1 and 4.2

  • Understanding of Infinity queries and JSONata


Overview

Dashboard variables create interactive dropdowns that let users filter data without editing queries. They're essential for:

  • Site selection – Choose which location to view

  • Machine selection – Filter to specific machines

  • Time period selection – Custom date ranges

  • Multi-user dashboards – One dashboard serves many needs

Variable Types

Type
Description
Use Case

Query

Values from API/database

Site, machine, product dropdowns

Custom

Fixed list of values

Shift names, status options

Text box

User-entered value

Search filters

Constant

Single hidden value

Base URLs, fixed IDs

Interval

Time intervals

Refresh rates


Creating Your First Variable

Let's create a site dropdown that queries the ENLYZE API.

Step 1: Open Variable Settings

  1. Open your dashboard

  2. Click the gear icon (Dashboard settings)

  3. Select Variables from the left menu

  4. Click Add variable

[SCREENSHOT: Dashboard settings with Variables menu]

Step 2: Configure Basic Settings

Setting
Value

Name

site

Type

Query

Label

Site

Hide

(leave empty - show variable)

Important: Variable names should be lowercase with no spaces. Use underscores if needed (e.g., machine_uuid).

[SCREENSHOT: Variable basic settings]

Step 3: Configure Query

Under Query Options:

  1. Set Data source to Infinity

  2. Set Query type to Infinity

The query editor appears. Configure it like a panel query:

Setting
Value

Type

JSON

Parser

Backend

Source

URL

URL

sites

Root selector

$.data

[SCREENSHOT: Variable query configuration]

Step 4: Configure Value Mapping

Scroll down to Value options:

Setting
Value
Description

Regex

(leave empty)

Filter results

Sort

Alphabetical (asc)

Order options

The dropdown needs to know which fields to display and store:

  • Display value: What users see (site name)

  • Stored value: What's used in queries (site UUID)

For Infinity variables, the first column becomes the display value, and if there's a second column, it becomes the stored value.

To control this, add columns to your query:

  1. Scroll to Columns in the query

  2. Add two columns:

Selector
Title
Type

name

Name

String

uuid

UUID

String

[SCREENSHOT: Column configuration for variable]

Step 5: Preview and Save

  1. Click Run query to preview values

  2. Verify the dropdown shows site names

  3. Click Apply to save

You should see the site dropdown at the top of your dashboard.

[SCREENSHOT: Site dropdown in dashboard]


Using Variables in Queries

Now use the ${site} variable in panel queries.

Filtering Machines by Site

Create a panel that shows machines for the selected site:

URL:

Root selector (JSONata filter):

This filters the machines array to only include those where the site matches the selected variable.

[SCREENSHOT: Panel showing filtered machines]

Variable Syntax

Syntax
Description
Example

${variable}

Basic substitution

${site}

${variable:raw}

No escaping

URL parameters

${variable:csv}

Comma-separated

Multi-select values

${variable:pipe}

Pipe-separated

Regex patterns


Chained Variables

Create a machine dropdown that updates when the site changes.

Step 1: Create Machine Variable

Add a new variable:

Setting
Value

Name

machine

Type

Query

Label

Machine

Step 2: Configure Query with Filter

Use JSONata to filter machines by the selected site:

Setting
Value

Type

JSON

URL

machines

Root selector

$filter($.data, function($v){ $v.site = "${site}" })

Add columns:

Selector
Title

name

Name

uuid

UUID

Step 3: Configure Refresh

Critical: Set refresh behaviour so machine options update when site changes:

Setting
Value

Refresh

On dashboard load

[SCREENSHOT: Chained variable configuration]

Step 4: Test the Chain

  1. Change the site dropdown

  2. Verify machine dropdown updates to show only machines at that site


Multi-Select Variables

Allow users to select multiple values.

Enabling Multi-Select

In variable settings:

Setting
Value

Multi-value

Enabled

Include All option

Enabled

[SCREENSHOT: Multi-select settings]

Using Multi-Select in Queries

Multi-select variables return multiple values. Handle them appropriately:

For URL parameters (comma-separated):

For JSONata filters:

For regex matching:


Hidden Variables

Some variables shouldn't be shown to users but are useful for queries.

Use Cases

  • Convert time formats

  • Store computed values

  • Hold intermediate results

Creating a Hidden Time Variable

Create a variable that converts Grafana's time to ISO format:

Setting
Value

Name

start_iso

Type

Query

Hide

Variable (completely hidden)

Query configuration:

Setting
Value

Source

Inline

Data

{"time": ${__from}}

Root selector

$fromMillis($number($.time))

Setting
Value

Refresh

On time range change

This converts the epoch milliseconds from ${__from} to ISO format.

[SCREENSHOT: Hidden variable configuration]

Hide Options

Value
Behaviour

(empty)

Show label and value

Label

Show value only

Variable

Completely hidden


Complete Example: Site > Machine Dashboard

Let's build a dashboard with chained site and machine dropdowns.

Variables to Create

  1. site – Site dropdown

  2. machine – Machine dropdown (filtered by site)

Variable 1: Site

Setting
Value

Name

site

Label

Site

Type

Query

Query URL

sites

Root selector

$.data

Columns

name, uuid

Sort

Alphabetical

Variable 2: Machine

Setting
Value

Name

machine

Label

Machine

Type

Query

Query URL

machines

Root selector

$filter($.data, function($v){ $v.site = "${site}" })

Columns

name, uuid

Refresh

On dashboard load

Using in Panels

Production Runs with OEE:

This returns production runs for the selected machine with OEE scores (productivity, availability, performance, quality) per run.

Variables (Sensor Data) Query:


Variable Display Options

In variable Display settings:

Display
Description
Best For

Dropdown

Standard select

Many options

Radio

Horizontal buttons

Few options (2-5)

Custom All Value

When "Include All" is enabled, you can customize what value "All" represents:

Setting
Value
Result

Custom all value

.*

Regex match all

Custom all value

$__all

All selected values


Troubleshooting Variables

Variable Shows No Values

Causes:

  1. Query returns no data

  2. Wrong root selector

  3. Columns not configured

Fix: Test the same query in a panel first.

Chained Variable Not Updating

Causes:

  1. Refresh not set correctly

  2. Parent variable name typo in filter

Fix: Set Refresh to "On dashboard load" and verify variable name in JSONata expression.

Multi-Select Returns Wrong Format

Cause: Not using proper format modifier

Fix: Use ${variable:csv} for comma-separated or ${variable:pipe} for pipe-separated.


Best Practices

Naming Conventions

  • Use lowercase: site, not Site

  • Use underscores: machine_uuid, not machineUuid

  • Be descriptive: production_line, not pl

Performance

  • Filter data in variables, not just in panels

  • Use "On dashboard load" refresh for dependent variables

  • Avoid excessive API calls with proper caching

User Experience

  • Use meaningful labels

  • Set sensible defaults

  • Hide technical variables from users

  • Order variables logically (site -> machine -> variable)


Summary

You've learned to create dynamic dashboards with variables:

  • Query variables from the ENLYZE API

  • Chain variables for dependent dropdowns

  • Use variables in Infinity queries with ${variable} syntax

  • Create multi-select and hidden helper variables


What's Next?

Continue with:


Quick Reference

Variable Query Settings

Setting
Value

Type

Query

Data source

Infinity

Query type

Infinity

Parser

Backend

Common Root Selectors

Purpose
JSONata Expression

All items

$.data

Filter by site

$filter($.data, function($v){ $v.site = "${site}" })

Filter by machine

$filter($.data, function($v){ $v.machine = "${machine}" })

Variable Modifiers

Modifier
Output
Use Case

${var}

Single value

Most queries

${var:csv}

a,b,c

URL parameters

${var:pipe}

a|b|c

Regex patterns

${var:raw}

Unescaped

Special characters

Refresh Options

Value
When

Never

Only on page load

On dashboard load

When dashboard opens

On time range change

When time picker changes

Last updated