cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

revoke7889
Newcomer

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:

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:

{
  "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

 

2 REPLIES 2

krzysztof_hoja
Dynatrace Champion
Dynatrace Champion

Last line should look like:

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

you can find more information on iterative expressions here: https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-query-language/operators#ite...

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

krzysztof_hoja_0-1754251764751.png

 

 

 

 

 

Thanks, working!

Featured Posts