Calculate Percentages in Dynatrace DQL Queries

Given two fields:

genCount = 2

vecEmbeddingCount = 2

I want to calculate the percentage of genCount of the total (ie. The result I’m looking for is 50%).

fetch logs
...
| fieldsAdd totalCount = genCount + vecEmbeddingCount
| fieldsAdd cacheHitRate = genCount / totalCount*100

hfdku_0-1715644544283.png

What am I missing?

Order of operations matters here, especially these are integer operations:
2/4*100 = 0*100 = 0
but

100*2/4 = 200/4 = 50.

Here is DQL example:

data record(genCount = 2,vecEmbeddingCount = 2)
| fieldsAdd totalCount = genCount + vecEmbeddingCount
| fieldsAdd cacheHitRate = genCount / totalCount*100
| fieldsAdd cacheHitRateCorrect = 100*genCount / totalCount

Kris

Where is it specified that these are integers (or integer operations)?
In fact, integers aren’t even mentioned in the DQL data types page - only double and long are listed.

This seems to work:

fetch logs
| summarize genCount = toDouble(countIf(matchesPhrase(content, "gpt-3.5"))),
            vecEmbeddingCount = toDouble(countIf(matchesPhrase(content, "text-embedding-ada-002")))
| fieldsAdd totalCount = genCount + vecEmbeddingCount
| fieldsAdd cacheHitRate = genCount / totalCount * 100
| fieldsKeep cacheHitRate

I did not mean “integer data type”, but meant “integer mathematical concept” (Integer - Wikipedia)

When you convert “long” numbers to “double” numbers (floating point) it will work too, but will be give you result in form of “double”. What type you want to get in the end of course depends on your requirements.

When you get result in form of floating point number, you can always get needed precision using round (Mathematical functions — Dynatrace Docs) or needed data type i.e. using toLong (Conversion and casting functions — Dynatrace Docs)

Re: “order of operations” which often matter when dealing with integers . DQL uses most common approach uses by programming languages (“left to right”), probably that’s why it was never mentioned in documentation. Example in second paragraph here covers similar case like ours: Order of operations - Wikipedia

Kris