# DQL percentage in a graph of two arrays (error versus total)

**URL:** <https://community.dynatrace.com/t/dql-percentage-in-a-graph-of-two-arrays-error-versus-total/52712>\
**Category:** DQL\
**Tags:** failure-rate, dql\
**Created:** [July 30, 2025, 6:41am UTC](https://community.dynatrace.com/t/dql-percentage-in-a-graph-of-two-arrays-error-versus-total/52712 "2025-07-30T06:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![revoke7889](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@revoke7889](https://community.dynatrace.com/u/revoke7889)\
**Post date:** [July 30, 2025, 6:41am UTC](https://community.dynatrace.com/t/dql-percentage-in-a-graph-of-two-arrays-error-versus-total/52712/1 "2025-07-30T06:41:18Z")

</div>

Hi community! Struggling with the following - is it possible to create a percentage calculation and show it in a Dynatrace dashboard visualization (timeseries graph)?

I have the following working DQL that includes two arrays: total and errors:

```markup
fetch logs
| filter dt.system.bucket == "kpi"
| filter matchesValue(applicationid, "XXX")
| parse content, "JSON:json"
// several filters...
| expand errorCode = json[data][errorCode]
| fieldsAdd isError = if(isNotNull(errorCode), 1, else: 0)
| makeTimeseries {total = count(), errors = sum(isError)}, time:{timestamp}, interval:{24h}
| fieldsAdd errorRate = if(total > 0, round(errors * 100.0 / total, decimals: 2), else: 0)

```

However the errorRate does not seem to work. Here is a snippet from the raw response:

```markup
{
  "records": [
    {
      "timeframe": {
        "start": "2025-07-23T00:00:00.000000000+02:00",
        "end": "2025-07-31T00:00:00.000000000+02:00"
      },
      "interval": "86400000000000",
      "total": [
        73229,
        98446,
        88787,
        89492,
        95227,
        87934,
        85991,
        21596
      ],
      "errors": [
        4487,
        6250,
        5598,
        5856,
        6691,
        6580,
        5673,
        1278
      ],
      "errorRate": "0"
    }
  ],
  "types": [
    {
      "indexRange": [
        0,
        0
      ],
      "mappings": {
        "timeframe": {
          "type": "timeframe"
        },
        "interval": {
          "type": "duration"
        },
        "total": {
          "type": "array",
          "types": [
            {
              "indexRange": [
                0,
                7
              ],
              "mappings": {
                "element": {
                  "type": "double"
                }
              }
            }
          ]
        },
        "errors": {
          "type": "array",
          "types": [
            {
              "indexRange": [
                0,
                7
              ],
              "mappings": {
                "element": {
                  "type": "double"
                }
              }
            }
          ]
        },
        "errorRate": {
          "type": "long"
        }
      }
    }
  ],

```

Do you know a way to make this work? Thanks.

Please note even when commenting out the last line, I can’t get error and total to be visualized:

 ![revoke7889_0-1753857766276.png](https://global.discourse-cdn.com/dynatrace/original/2X/7/734222ab552a5d7f8772dc43fba88e67f788cf8d.png)

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [August 3, 2025, 8:09pm UTC](https://community.dynatrace.com/t/dql-percentage-in-a-graph-of-two-arrays-error-versus-total/52712/2 "2025-08-03T20:09:45Z")

</div>

Last line should look like:

```markup
| fieldsAdd errorRate = if(total[] > 0, round(errors[] * 100.0 / total[], decimals: 2), else: 0)

```

you can find more information on iterative expressions here:&nbsp;[DQL operators — Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-query-language/operators#iterative-expressions)

My result on slightly different data, but with 2 last lines kept:

 ![krzysztof_hoja_0-1754251764751.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/0fc0c1718bdcdac35874ee87c38d37923294ddfc.png)

---

<div class="post-metadata">

**Author:** ![revoke7889](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@revoke7889](https://community.dynatrace.com/u/revoke7889)\
**Post date:** [August 5, 2025, 7:30am UTC](https://community.dynatrace.com/t/dql-percentage-in-a-graph-of-two-arrays-error-versus-total/52712/3 "2025-08-05T07:30:30Z")

</div>

Thanks, working!
