I’ve been working with Grafana for a while, and I have a question about query referencing within the same panel. Specifically, I would like to know if it’s possible to reference the output of Query A in Query B within the same panel.
I’m attempting to apply some complex transformations, and it seems like referencing one query’s output from another is the most straightforward approach.
Is there a recommended way to achieve this, or any alternative methods I should consider?
Thank you in advance for your guidance and suggestions!
In Query A, I am using Redis as the data source and have attached its output. In Query B (possibly SQL as datasource), I want to use the complete output of Query A to dynamically find the minimum and maximum values and apply color coding accordingly.
I am aware that transformations can be used to find the min and max, but they create separate columns for each. Instead, I am looking for a way to determine these values within a query and label them as ‘min’ and ‘max’ for color coding.
I previously achieved the same result using TimescaleDB, but the query was quite complex as it involved both data retrieval and manipulations.So i’m switching to Redis and want to find a way to do the same
Index,Voltage (V)
01,3.285 V
02,3.285 V
03,3.285 V
04,3.285 V
05,3.287 V
06,3.285 V
07,3.287 V
08,3.287 V
09,3.285 V
10,3.285 V
11,3.285 V
12,3.285 V
13,3.285 V
14,3.287 V
15,3.287 V
16,3.287 V
For Query 2, the values remain the same, but color coding is applied based on the minimum and maximum values.
You can do query A in a variable, select all values, and do query B as a normal one, using the variable generated in the first query. You can hide the variable to this be transparent to the user.
I did color coding in a table but it was tricky because getting cell config from the query results is not well documented.
To do this you have to extract that row along with its date and value and plot as a point with its own colour and point size.
The easiest way to do this is to use query A, duplicate as QueryB, and do a sort on that variable so the largest value appears in the top row then just use the top row, and use the override function to select colour or point size etc as shown below
Note I have used many metering systems and very few include the MD valuie and date in any query. It is a tricky query to find the max value in any array and then find its accompanying data. So I just did the above and it works like a charm apart from a little PT.
Hope this helps?
I may have read your post incorrectly so is this what you require?