Can I transfer filter settings from one panel to another?

I have a table panel which displays product / stock information sourced from a SQL query.

Users can filter this table in Grafana by product name, e.g. all products containing the word “plastic”. This way the user can see all the different “plastic” products and how many of each were shipped.

What I’d like to do is have a second panel next to the table which shows the sums for all the filtered rows.

For example, a stats panel that would show the total quantity or value, of all “plastic”, “wood” or whatever filter the user selected in the first panel.

I’m struggling to think of a way to achieve this:

  • I don’t think it can be included in the original table, because it’s a single value, not a column of values
  • I don’t think there’s a way to transfer the user’s filter from one panel to another
  • Due to the quantity of products, e.g. there’s 300 “plastic” products, using a query variable is not feasible
  • Panel links nor repeating panels seem to work this way

Is it possible to achieve this? How would you do it?

the sum of what value?

Sorry, I see the confusion. If the first table is this:

Product Name Value Quantity
wood_chair 20 30
wood_table 100 10
plastic_chair 15 80

And you filtered for “wood”, then the second table would be:

Total Value Total Quantity
1,600 40

I can configure the query or the table transformations to return the Total Value and Total Quantity as shown, but what I cannot do is get the filter from the first table (in this case “wood”) to apply to the second table, so that it only counts rows which match that filter.

Why not use the Total feature of the table panel?

Because in that case, the “Total Value” is not actually the sum of the values, but the sum of (quantity * value).

The Total Quantity will work the way you suggested.

If I can make the table footer show sum(value * quantity) for Total Value and sum(quantity) for Total Quantity, then I’d be happy with that solution.

1 Like

what is your data source?

PostgreSQL 15


you need to do your aggregation in postgres first and use this amazing plugin by @mikhailvolkov team

below is just mock data but you can see what I am doing.

;with src
as
(
  select 'wood_chair' product,	20 value,	30 quantity union
  select 'wood_table',	100,	10 union
  select 'plastic_chair',	15,	80
)
select src.*, tots.total_value, tots.total_quantity
  from src 
join (
  select product, sum(value * quantity) as total_value, 
         sum(quantity) as total_quantity
    from src
    where product like '%' + '${filter}' + '%'
    group by product
) tots on src.product = tots.product
where src.product like '%' + '${filter}' + '%'
2 Likes

Fantastic, thank you - I’ll give this a try!

1 Like