# How to aggregate multiple CloudWatch metrics into a single total for success rate calculation?

**URL:** <https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140>\
**Category:** Configuration\
**Tags:** transformations, cloudwatch, aws\
**Created:** [November 5, 2025, 5:22pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140 "2025-11-05T17:22:47Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 5, 2025, 5:22pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/1 "2025-11-05T17:22:47Z")

</div>

Hello,

I am looking for advice on how to agregate multiple numeric values into a single value from a list of dimension values.

- What Grafana version and what operating system are you using?

Amazon Managed Grafana 10.4.1 using the cloudwatch data source

- **What** are you trying to achieve?

We are creating success rate panels using Stats.

Example will use Lambda, but same issue with API Gateway and other queries with multiple dimensions like this.

- **How** are you trying to achieve it?

Starting with a query variable $function. This is a list of all FunctionNames to include.

In a visualisation, there are 2 Cloudwatch metrics queries, one for Invocations and another for Errors, each grouped by FunctionName.

Passing in $function as the dimension value for FunctionName successfully retrieves the time series data for Invocations/Errors of the listed functions.

Each query is passed to a Reduce expression and that reduce is then used in a math expression.

- What happened?

For queries where there’s no dimension passed, or where there is a single dimension passed, this works.

For multiple functions, the sums are still grouped by FunctionName.

- What did you **expect** to happen?

For this panel, we need to have a Total of all the Invocations/Erros combined to be used in the calculation.

- Can you copy/paste the configuration(s) that you are having problems with?

Example Panel JSON:

```auto
{
  "datasource": {
    "uid": "${datasource}",
    "type": "cloudwatch"
  },
  "fieldConfig": {
    "defaults": {
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "#3274D9",
            "value": null
          },
          {
            "color": "dark-red",
            "value": 85
          },
          {
            "color": "#EAB839",
            "value": 99.5
          },
          {
            "color": "dark-green",
            "value": 100
          }
        ]
      },
      "unit": "percent"
    },
    "overrides": []
  },
  "gridPos": {
    "h": 15,
    "w": 15,
    "x": 0,
    "y": 12
  },
  "id": 4,
  "options": {
    "reduceOptions": {
      "values": false,
      "calcs": [],
      "fields": ""
    },
    "orientation": "auto",
    "textMode": "auto",
    "wideLayout": true,
    "colorMode": "background_solid",
    "graphMode": "area",
    "justifyMode": "center",
    "showPercentChange": true
  },
  "pluginVersion": "10.4.1",
  "title": "Lambda example",
  "type": "stat",
  "targets": [
    {
      "datasource": {
        "type": "cloudwatch",
        "uid": "..."
      },
      "id": "",
      "region": "default",
      "logGroups": [],
      "queryMode": "Metrics",
      "namespace": "AWS/Lambda",
      "metricName": "Invocations",
      "expression": "",
      "dimensions": {
        "FunctionName": "$function"
      },
      "statistic": "Sum",
      "period": "",
      "metricQueryType": 0,
      "metricEditorMode": 0,
      "sqlExpression": "",
      "matchExact": true,
      "stat": "Sum",
      "refId": "Invocations",
      "label": "",
      "hide": true
    },
    {
      "datasource": {
        "type": "cloudwatch",
        "uid": "..."
      },
      "id": "",
      "region": "default",
      "logGroups": [],
      "queryMode": "Metrics",
      "namespace": "AWS/Lambda",
      "metricName": "Errors",
      "expression": "",
      "dimensions": {
        "FunctionName": "$function"
      },
      "statistic": "Sum",
      "period": "",
      "metricQueryType": 0,
      "metricEditorMode": 0,
      "sqlExpression": "",
      "matchExact": true,
      "stat": "Sum",
      "refId": "Errors",
      "label": "",
      "hide": true
    },
    {
      "datasource": {
        "type": " __expr__",
        "uid": " __expr__",
        "name": "Expression"
      },
      "refId": "ReducedInvocations",
      "type": "reduce",
      "hide": true,
      "reducer": "sum",
      "expression": "Invocations",
      "settings": {
        "mode": "replaceNN",
        "replaceWithValue": 0
      }
    },
    {
      "datasource": {
        "type": " __expr__",
        "uid": " __expr__",
        "name": "Expression"
      },
      "refId": "ReducedErrors",
      "type": "reduce",
      "hide": true,
      "reducer": "sum",
      "expression": "Errors",
      "settings": {
        "mode": "replaceNN",
        "replaceWithValue": 0
      }
    },
    {
      "refId": "SuccessRate",
      "type": "math",
      "hide": false,
      "expression": " ((${ReducedInvocations} - ${ReducedErrors}) / (${ReducedInvocations})) * 100"
    }
  ],
  "transformations": [
    {
      "id": "renameByRegex",
      "options": {
        "regex": "SuccessRate.*",
        "renamePattern": "SuccessRate"
      }
    }
  ]
}

```

- Did you receive any errors in the Grafana UI or in related logs? If so, please tell us **exactly** what they were.

No errors.

- Did you follow any online instructions? If so, what is the URL?

I have searched the forum for similar issues and found this: [Summing all fields matching certain pattern - #2 by usman.ahmad](https://community.grafana.com/t/summing-all-fields-matching-certain-pattern/69759/2)

The Rename by regex transformation successfully renames from FunctionName to SuccessRate, but then reducing with Add field from calculation does not produce a sum total of all the functions.

Please let me know if there’s any more info needed.  
Thanks,

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 5, 2025, 8:48pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/2 "2025-11-05T20:48:56Z")

</div>

What visualization do you want to use at the end to show this value?

Can you please share the table view of your data if possible ?

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 6, 2025, 10:06am UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/3 "2025-11-06T10:06:47Z")

</div>

Hi @yosiasz,

Thanks for responding.

The aim is to display a single percentage based on a math calculation. Very simple when working with a small number of functions. The example in the image shows two queries with a single function name hard coded, Invocations and Errorrs, two reduce expressions, and then a math expression to create the percentage.

 ![example_single_function](https://us1.discourse-cdn.com/grafana/original/3X/7/0/707aad6ebf7c77f48523f7950d8ba19ce386f141.png)

This is the target JSON to query a single with a single function in the FunctionName dimension

```auto
    {
      "id": "",
      "region": "default",
      "logGroups": [],
      "queryMode": "Metrics",
      "namespace": "AWS/Lambda",
      "metricName": "Invocations",
      "expression": "",
      "dimensions": {
        "FunctionName": "functionName"
      },
      "statistic": "Sum",
      "period": "",
      "metricQueryType": 0,
      "metricEditorMode": 0,
      "sqlExpression": "",
      "matchExact": true,
      "datasource": {
        "uid": "${datasource}",
        "type": "cloudwatch"
      },
      "refId": "A",
      "hide": false,
      "label": ""
    }

```

Data table view would be as such:

| Time | Invocations |
| --- | --- |
| 2025-11-06 14:12:00 | 6 |
| 2025-11-06 08:40:00 | 9 |
| 2025-11-06 08:23:00 | 3 |

Errors works the same.

In our case, we pass a list of functions from a query variable as $functions

```auto
    {
      "id": "",
      "region": "default",
      "logGroups": [],
      "queryMode": "Metrics",
      "namespace": "AWS/Lambda",
      "metricName": "Invocations",
      "expression": "",
      "dimensions": {
        "FunctionName": "$functions"
      },
      "statistic": "Sum",
      "period": "",
      "metricQueryType": 0,
      "metricEditorMode": 0,
      "sqlExpression": "",
      "matchExact": true,
      "datasource": {
        "uid": "${datasource}",
        "type": "cloudwatch"
      },
      "refId": "A",
      "hide": false,
      "label": ""
    }

```

Data table view now shows a drop down with each FunctionName and the data looks like this:

| Time | FunctionName |
| --- | --- |
| 2025-11-06 14:12:00 | 6 |
| 2025-11-06 08:40:00 | 9 |
| 2025-11-06 08:23:00 | 3 |

This creates multple values in the panel, which is not desired.

 ![multi_function_example](https://us1.discourse-cdn.com/grafana/original/3X/6/f/6fc8119f0407e97327af94ca38b6b188ae6e6a64.png)

What we are trying to do is sum the data from each function into a single value before the math expression - e.g. AllInvocations and AllError.

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 6, 2025, 10:19am UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/4 "2025-11-06T10:19:31Z")

</div>

You can use CloudWatch math:

> [@How to populate CloudWatch metric with zeros?](https://community.grafana.com/t/how-to-populate-cloudwatch-metric-with-zeros/125950/6):
>
> I think you don’t understand. You can write CloudWatch metric math in CloudWatch console - that “e1 series”. You can write exactly the same CloudWatch metric math in Grafana queries - you have different UI, but it will be the same. Please study this SLO - IMHO exactly your case, I don’t use generic m1,m2,e1 IDs, but more meaningful names in IDs: Use doc to understand used CloudWatch metric math functions, operators, …, e.g. FILL:

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 6, 2025, 12:47pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/5 "2025-11-06T12:47:31Z")

</div>

Hi @jangaraj,

Thanks for responding.

I think the thread you have linked does not fully answer my question.

The example panel takes a variable that is a **single** load balancer name, not a **list**.  
Using a list of load balancer names would cause the IF function in that example to error because of the multiple dimensions.

With a single value:

 ![single-function-cloudwatch-math](https://us1.discourse-cdn.com/grafana/original/3X/a/5/a5cc05309a9d842f30f73bdc7101cc4beeb9e71f.png)

With a list:

 ![list-cloudwatch-math-error](https://us1.discourse-cdn.com/grafana/original/3X/f/1/f1786775b3616b6461603e17db450185d1215556.png)

Whether it’s Grafana or CloudWatch math is not particularlly important. But having multiple dimensions in the query is still the issue. Do you know a way to aggregate the dimension values using cloudwatch math?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 6, 2025, 2:49pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/6 "2025-11-06T14:49:16Z")

</div>

I don’t think you can have a list here:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/0/6/062577a2005bb914598afe79097002e699d71906.png)

It can be single value, or ‘\*’. IMHO that is CloudWatch API limitation, not Grafana limitation.  
Can you use list in the filter in the AWS CloudWatch console?

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 6, 2025, 3:17pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/7 "2025-11-06T15:17:29Z")

</div>

Actually, it can be a list. I also didn’t think this would work, as you are right that this kind of thing is not possible in CW console. But here’s a screenshot with table view as proof:

 ![listOfFunctionNamesWorking](https://us1.discourse-cdn.com/grafana/original/3X/6/5/65a03260fc85018e7320c19430b225a3b49e8260.png)

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 6, 2025, 3:51pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/8 "2025-11-06T15:51:33Z")

</div>

![image](https://us1.discourse-cdn.com/grafana/original/3X/8/1/8184d9592b06d93a6f584d44a349b4131a0db701.png)

You have error in expression - you need to play more with that - maybe that’s too much for this query language.

> **[Using math expressions with CloudWatch metrics - Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html)**
>
> Steps to use math expressions with CloudWatch metrics to create new time series.

You may try SQL like CloudWatch query language -

> **[Use natural language to generate and update CloudWatch Metrics Insights...](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-metrics-insights-query-assist.html)**
>
> Learn how to create queries using natural language.

I would say first create query in AWS console and then you can replicate that in Grafana.

Another option, IMHO the most promising is to use Grafana SQL expression.

> **[SQL expressions | Grafana documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/sql-expressions/)**
>
> Manipulate and transform data in Grafana using SQL expressions.

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 6, 2025, 4:42pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/9 "2025-11-06T16:42:48Z")

</div>

I also was going to definitely recommend sql expression to tie it all up

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 6, 2025, 4:45pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/10 "2025-11-06T16:45:43Z")

</div>

That error in the CW math is not relevant. It’s because the type is a TS not a TS. I made that panel based on your example to demonstrate that the issue with multiple dimensions remains. As SUM does not aggregate dimension values, I do not think CloudWatch math will work.

Unfortunately, there are too many issues with using SQL Cloudwatch in Grafana at present. For one, you can only run a single query in a panel. Additionally, OR is not valid keyword, only AND.

Valid (but no data obv)

 ![sql-and](https://us1.discourse-cdn.com/grafana/original/3X/4/2/42e0ba3dcceb6268f45ee5cf75cdeb0607b36658.png)

Invalid

 ![sq-or](https://us1.discourse-cdn.com/grafana/original/3X/4/7/47f7e402574abdbdaa43899ab9fbb7588c424054.png)

So this cannot be used on multiple FunctionNames.

Builder mode for Metrics Query does not quote the metric names, causing errors where Count is both a metric and a reserved keyword, for example. But I digress…

Given that I have successfuly retreived the data I need using the Metrics Search in Builder mode, all I need is a way to aggregate the dimensions.

Surely, this must be possible?

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 6, 2025, 8:46pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/11 "2025-11-06T20:46:52Z")

</div>

Sql expression was recommended, try that

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 7, 2025, 11:50am UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/12 "2025-11-07T11:50:29Z")

</div>

Hi @yosiasz

Please see the reply I made to @jangaraj. I have used SQL as you can see in the screenshots.

Without OR how can I query for multiple lambda functions?

This still doesn’t answer the fundamental issue either. How do I aggregate the dimensions in a SQL statement?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 7, 2025, 12:01pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/13 "2025-11-07T12:01:39Z")

</div>

> [@scl67](#):
>
> I have used SQL as you can see in the screenshots.

That’s “CloudWatch SQL”. But recommendation is to use “Grafana SQL”.

So you have your CloudWatch query with that terrible format. Grafana will convert CloudWatch query results into temp SQL tables and you can apply mature SQL query langues on the top. I’m linking already linked doc:

> **[SQL expressions | Grafana documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/sql-expressions/)**
>
> Manipulate and transform data in Grafana using SQL expressions.

---

<div class="post-metadata">

**Author:** ![scl67](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@scl67](https://community.grafana.com/u/scl67)\
**Post date:** [November 7, 2025, 1:24pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/14 "2025-11-07T13:24:05Z")

</div>

This is a preview feature and cannot be enabled in managed grafana.

Back to square one 😞

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 7, 2025, 2:39pm UTC](https://community.grafana.com/t/how-to-aggregate-multiple-cloudwatch-metrics-into-a-single-total-for-success-rate-calculation/159140/15 "2025-11-07T14:39:32Z")

</div>

It’s AMP, so AWS is supporting that = you can ask your AWS support in this case.
