30 Jul 2025 07:41 AM - edited 30 Jul 2025 07:42 AM
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:
Solved! Go to Solution.
03 Aug 2025 09:09 PM
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: