Sum multiple series with the same name

Grafana 11.4 with a Zabbix 7.2 data-source.

A Grafana Stat panel queries Zabbix and returns multiple metrics from different hosts, each with similar series names. For example:

Series 20 = 1
Series 20 = 2
Series 22 = 1
Series 22 = 3
Series 22 = 1
Series 43 = 10
Series 43 = 0
(...)

Despite the repeated name, each series may have a different “last value”.

I need to sum the last value of all metrics that have the same series name. Something like this:

Series 20 = 3
Series 22 = 5
Series 43 = 10
(...)

I tried a few transformations, but they did not work.
Any thoughts on this matter?

Hi, I think transformation '“Group by” will be what you’re looking for - group by name and calculate the value using Total function

1 Like

Contrary to its name, the Group by transformation doesn’t work as expected in my scenario.

Here’s a picture of the query data:

We see that there are multiple metrics with equal names. About 7 for each series.

I’ve added a name filter just to make it easier to work with.


The Group by transformation shows the warning message Calculations will not have an effect if no fields are being grouped on.

Ok, so it’s like that. Can you use Reduce transformation with Series to rows mode (I think Last calculation should be fine for your case). Then use Group by transformation.

what does the data look like in the in the Table view setting

The current query produces multiple series.
The table view shows the values for each series selected in the selection box.

However, when I add the Reduce transformation, “no data” is found.

so in the case of the data you are showing in that screen shot it corresponds to Series 37 in the original sample data you posted? The closer to real data as is on your side you show the easier and quicker to get to a probable solution.

When you post


Series 37= 1
Series 20 = 2
Series 22 = 1
Series 22 = 3
Series 22 = 1
Series 43 = 10

we might make assumptions :wink:

So in the case of 37 which one would be the “last value” as there are dups, unless my eyes are failing me

I’m not sure why the data was duplicated in that pic. I didn’t notice then. However, the idea hasn’t changed.

Let’s look into the following test scenario.

I’ve added the following queries to illustrate my point.


We can see that there are multiple series with the same name. Some are CPU utilization 1 and others are CPU utilization 2. The same applies to the initial dataset I provided as an example.

The data is not presented in a table with a column for each series. In the table view, we see that the data is separated by a selection box.

Again, we see multiple series with equal names, but each has its own values.


So, I wish to sum the last value of each series with an equal name. However, the group by transformation does not work in this scenario.



The Reduce with Series to rows transformation does not create a column for each series; it places them all in the same column.

I can apply a group by after using Reduce.

However, after unchecking table view, it does not display all values.

Ok, so we’re almost there. Now after you have used group by transformation, change the option of the stat visualization (on the right side). Look for Value Options section, then under “Show” instead of default “Calculate” pick “All values”

2 Likes

That was it! Now I can see all values.

The “Show” All values option was the missing piece.

Its also good to check the Limit option when there are many values to display.

Thanks a lot, guys!

1 Like