<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate a percentage? in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245494#M885</link>
    <description>&lt;P&gt;Where is it specified that these are integers (or integer operations)?&lt;BR /&gt;In fact, integers aren't even mentioned in the &lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/data-types" target="_blank"&gt;DQL data types page&lt;/A&gt; - only double and long are listed.&lt;/P&gt;&lt;P&gt;This seems to work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 14 May 2024 06:39:39 GMT</pubDate>
    <dc:creator>hfdku</dc:creator>
    <dc:date>2024-05-14T06:39:39Z</dc:date>
    <item>
      <title>Calculate Percentages in Dynatrace DQL Queries</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245483#M883</link>
      <description>&lt;P&gt;Given two fields:&lt;/P&gt;
&lt;P&gt;genCount = 2&lt;/P&gt;
&lt;P&gt;vecEmbeddingCount = 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate the percentage of genCount of the total (ie. The result I'm looking for is 50%).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch logs
...
| fieldsAdd totalCount = genCount + vecEmbeddingCount
| fieldsAdd cacheHitRate = genCount / totalCount*100&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hfdku_0-1715644544283.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19790i5A7A54713A6B3D49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hfdku_0-1715644544283.png" alt="hfdku_0-1715644544283.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What am I missing?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 08:46:44 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245483#M883</guid>
      <dc:creator>hfdku</dc:creator>
      <dc:date>2025-12-19T08:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a percentage?</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245491#M884</link>
      <description>&lt;P&gt;Order of operations matters here, especially these are integer operations:&lt;BR /&gt;2/4*100 = 0*100 = 0&lt;BR /&gt;but&lt;/P&gt;&lt;P&gt;100*2/4 = 200/4 = 50.&lt;BR /&gt;&lt;BR /&gt;Here is DQL example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data record(genCount = 2,vecEmbeddingCount = 2)
| fieldsAdd totalCount = genCount + vecEmbeddingCount
| fieldsAdd cacheHitRate = genCount / totalCount*100
| fieldsAdd cacheHitRateCorrect = 100*genCount / totalCount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1715665377589.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19793i2CE906859BF13E7D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="krzysztof_hoja_0-1715665377589.png" alt="krzysztof_hoja_0-1715665377589.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 05:43:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245491#M884</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-05-14T05:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a percentage?</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245494#M885</link>
      <description>&lt;P&gt;Where is it specified that these are integers (or integer operations)?&lt;BR /&gt;In fact, integers aren't even mentioned in the &lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/data-types" target="_blank"&gt;DQL data types page&lt;/A&gt; - only double and long are listed.&lt;/P&gt;&lt;P&gt;This seems to work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 May 2024 06:39:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245494#M885</guid>
      <dc:creator>hfdku</dc:creator>
      <dc:date>2024-05-14T06:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a percentage?</title>
      <link>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245502#M886</link>
      <description>&lt;P&gt;I did not mean "integer data type", but meant "integer mathematical concept" (&lt;A href="https://en.wikipedia.org/wiki/Integer" target="_blank"&gt;https://en.wikipedia.org/wiki/Integer&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;When you get result in form of floating point number, you can always get needed precision using &lt;STRONG&gt;&lt;EM&gt;round&lt;/EM&gt; &lt;/STRONG&gt;(&lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/mathematical-functions#round" target="_blank"&gt;https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/mathematical-functions#round&lt;/A&gt;) or needed data type i.e. using &lt;EM&gt;&lt;STRONG&gt;toLong&lt;/STRONG&gt;&lt;/EM&gt; (&lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/conversion-and-casting-functions#toLong" target="_blank"&gt;https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/conversion-and-casting-functions#toLong&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;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:&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Order_of_operations#Programming_languages" target="_blank"&gt;https://en.wikipedia.org/wiki/Order_of_operations#Programming_languages&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 07:51:19 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Calculate-Percentages-in-Dynatrace-DQL-Queries/m-p/245502#M886</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-05-14T07:51:19Z</dc:date>
    </item>
  </channel>
</rss>

