Referencing Query Outputs Within the Same Panel in Grafana

Hello Grafana Community,

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! :slight_smile:

I think the recommended way is to do it in the query itself :wink:

1 Like

What is your data source?

Please share some sample data from both query a and b

And what part of the data from a you want to reference in B

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 :sweat_smile:

still waiting for you to provide the above sample data

For Query 1, the output is as follows:

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.

For Query 1, the output is as follows:

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.

For some reason the system has temporarily hidden the data reply :smiling_face_with_tear: what do i do

share your data with all of the columns (but you can change the column names) on some hosting site as csv

this is the output of Query A
i hope this helps

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.

1 Like

The simple answer is yes you may do it. I show an example below where in the load profile I have marked the PQ ans S max values as points.

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

To do this I just use the infinity data source and use UQL in the jason data
parse-json

I then use the transformations to join all the queries into a single table and rename or exclude what I require and voilà we have it.

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?