Repeat Panel Query based on variable

In one graph panel, I would like to repeat a query (query A, query B, etc) based on a multi value variable. I know I can repeat the panel based on the variable, but I’d rather have query repeat in the same panel so all the values are plotted in the same graph panel.

The basic syntax for my query is: SELECT column_name FROM $variable_name

Is this possible?

1 Like

You’re exactly right that with ‘repeat’ turned on in a panel, you’ll get one panel for each unique value.

Your example is pretty abstract, tough to get your direction, but the following URLs:

…show how to use wild cards (aka regex) to kinda behave like multiple queries. If that’s not helpful, perhaps provide a little more detail on what you’re after.

–Erik

Hi @nkoetje
I am also trying to repeat queries for multiple values in the same panel instead of panel repetition.
Did you find any solution for the issue ?

1 Like

I solved this (if I understand the question correctly) for a time series by using a GROUP BY statement:

SELECT
  time AS "time",
  AVG(${metric:raw}) AS "${metric:raw}",
  pico_id
FROM ambient_data
GROUP BY
  pico_id, time
ORDER BY 1

The aggregation function you choose (AVG, MAX, MIN or whatever) doesn’t matter if there’s only one value for a particular timestamp.

1 Like

Small addition: if you have multiple series (as in my case) you might want to make it respond to the variable selector.

For example, I’ve got three different metrics:

  • temp
  • pressure
  • humidity

And three different rooms:

  • cellar
  • bedroom
  • spare bedroom

If only e.g. bedroom is selected, the query above will still show data for all rooms. To get around this I added a WHERE statement after FROM:

WHERE INITCAP(pico_id) IN (${room})

… the INITCAP is just there because my variables are capitalised but the pico_id field in the database isn’t.

So the full query is:

SELECT
  time AS "time",
  MAX(${metric:raw}) AS "${metric:raw}",
  pico_id
FROM ambient_data
WHERE INITCAP(pico_id) IN (${room})
GROUP BY
  pico_id, time
ORDER BY 1