<?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: Conditional DQL statements based on value of input variable in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256602#M1226</link>
    <description>&lt;P&gt;variables are always strings and are treated as literals in DQL query. They cannot be used as a field names, commands or function names. The workaround is possible using this trick:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data record(a=1, b="a"),
record(a=1, b="a"),
record(a=2, b="b"),
record(a=2, b="b"),
record(a=2, b="b"),
record(a=3, b="c"),
record(a=3, b="d"),
record(a=3, b="e"),
record(a=3, b="e"),
record(a=4, b="e")
| fieldsAdd split=coalesce(
  if($splitField=="a", a),
  if($splitField=="b", b)
)
| summarize cnt=count(), by: { split }&lt;/LI-CODE&gt;&lt;P&gt;depending on variable value, proper field value will be kept under added filed of the same name independent from the choice. Now it can be directly used in a query (in by: {}).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1726826271904.png" style="width: 825px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22696i34382E33ECCC31C6/image-dimensions/825x295?v=v2" width="825" height="295" role="button" title="krzysztof_hoja_0-1726826271904.png" alt="krzysztof_hoja_0-1726826271904.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_1-1726826302237.png" style="width: 841px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22697i0D136A0D9572D18D/image-dimensions/841x329?v=v2" width="841" height="329" role="button" title="krzysztof_hoja_1-1726826302237.png" alt="krzysztof_hoja_1-1726826302237.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2024 09:59:06 GMT</pubDate>
    <dc:creator>krzysztof_hoja</dc:creator>
    <dc:date>2024-09-20T09:59:06Z</dc:date>
    <item>
      <title>Conditional DQL statements based on value of input variable</title>
      <link>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256566#M1225</link>
      <description>&lt;P&gt;I have some DQL that presents a table of data of web service calls.&amp;nbsp; The data can be examined in different ways e.g. by consumer_id or application_name etc.&amp;nbsp; &amp;nbsp;To achieve this I either have to edit query each time or create multiple tables on a dashboard.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I avoid this?&amp;nbsp; Can I create an input variable called Choice (holding different DQL text) and then use that to visualise the data from different views?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Summarise the output... 
| summarize hit_count = count(),by:{ $Choice, response_out_http_code }&lt;/LI-CODE&gt;&lt;P&gt;When I used the above&amp;nbsp; the $Choice resolves to the string "consumer_id" but the DQL is treating it as a string literal and not actually using it in the query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What&amp;nbsp; am I doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 07:45:36 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256566#M1225</guid>
      <dc:creator>HeadScratcher</dc:creator>
      <dc:date>2024-09-20T07:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional DQL statements based on value of input variable</title>
      <link>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256602#M1226</link>
      <description>&lt;P&gt;variables are always strings and are treated as literals in DQL query. They cannot be used as a field names, commands or function names. The workaround is possible using this trick:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data record(a=1, b="a"),
record(a=1, b="a"),
record(a=2, b="b"),
record(a=2, b="b"),
record(a=2, b="b"),
record(a=3, b="c"),
record(a=3, b="d"),
record(a=3, b="e"),
record(a=3, b="e"),
record(a=4, b="e")
| fieldsAdd split=coalesce(
  if($splitField=="a", a),
  if($splitField=="b", b)
)
| summarize cnt=count(), by: { split }&lt;/LI-CODE&gt;&lt;P&gt;depending on variable value, proper field value will be kept under added filed of the same name independent from the choice. Now it can be directly used in a query (in by: {}).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1726826271904.png" style="width: 825px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22696i34382E33ECCC31C6/image-dimensions/825x295?v=v2" width="825" height="295" role="button" title="krzysztof_hoja_0-1726826271904.png" alt="krzysztof_hoja_0-1726826271904.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_1-1726826302237.png" style="width: 841px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/22697i0D136A0D9572D18D/image-dimensions/841x329?v=v2" width="841" height="329" role="button" title="krzysztof_hoja_1-1726826302237.png" alt="krzysztof_hoja_1-1726826302237.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 09:59:06 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256602#M1226</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-09-20T09:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional DQL statements based on value of input variable</title>
      <link>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256623#M1229</link>
      <description>&lt;P&gt;I thought there must be a way.&amp;nbsp; &amp;nbsp; &amp;nbsp;That is a pretty neat solution and actually helps tidy up my DQL a little bit too.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 13:20:06 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/256623#M1229</guid>
      <dc:creator>HeadScratcher</dc:creator>
      <dc:date>2024-09-20T13:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional DQL statements based on value of input variable</title>
      <link>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/276444#M2030</link>
      <description>&lt;P&gt;Heyy&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now you can use variables not as a string literal by adding the&amp;nbsp;:noquote to the variable name for example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// for refrence writing the variable value
$Problam_Columns = "event.kind"


fetch dt.davis.problems 
| limit 1
| fields $Problam_Columns:noquote

// the "code" that will be used 
fetch dt.davis.problems 
| limit 1
| fields event.kind
 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also here is the link for the docs for that:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.dynatrace.com/docs/analyze-explore-automate/dashboards-and-notebooks/dashboards-new/components/dashboard-component-variable#dollarvarname-noquote" target="_blank"&gt;https://docs.dynatrace.com/docs/analyze-explore-automate/dashboards-and-notebooks/dashboards-new/components/dashboard-component-variable#dollarvarname-noquote&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 04 May 2025 15:31:30 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Conditional-DQL-statements-based-on-value-of-input-variable/m-p/276444#M2030</guid>
      <dc:creator>almog42</dc:creator>
      <dc:date>2025-05-04T15:31:30Z</dc:date>
    </item>
  </channel>
</rss>

