<?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: How to add a conditional where based on the field existence? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-a-conditional-where-based-on-the-field-existence/m-p/482781#M135225</link>
    <description>&lt;P&gt;hi @jieli,&lt;/P&gt;

&lt;P&gt;Try this. Here &lt;STRONG&gt;pcc&lt;/STRONG&gt; will be set to "" values when &lt;STRONG&gt;cityCode&lt;/STRONG&gt; not exists in the events and &lt;CODE&gt;like&lt;/CODE&gt; matches "" values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mvexpand metrics | spath input=metrics | eval pcc = if(isnotnull(cityCode), cityCode, "") | where if($selected_pcc|s$="all",like(pcc,"%"),like(pcc,$selected_pcc|s$)) | stats count as Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Apr 2020 16:29:41 GMT</pubDate>
    <dc:creator>manjunathmeti</dc:creator>
    <dc:date>2020-04-24T16:29:41Z</dc:date>
    <item>
      <title>How to add a conditional where based on the field existence?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-a-conditional-where-based-on-the-field-existence/m-p/482780#M135224</link>
      <description>&lt;P&gt;&lt;CODE&gt;mvexpand metrics | spath input=metrics | rename "cityCode" as pcc | where if($selected_pcc|s$="all",like(pcc,"%"),like(pcc,$selected_pcc|s$)) | stats count as Total&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I use the command above to filter the result by looking into the json field cityCode, and verify if the value equals to my dropdown value selection, by default all cityCode would be included (&lt;CODE&gt;%&lt;/CODE&gt;).&lt;BR /&gt;
The issue is when the message does not have the &lt;CODE&gt;cityCode&lt;/CODE&gt; field, the default select All cityCode will not work since the like (pcc,"%") would fail.&lt;/P&gt;

&lt;P&gt;Currently, the conditional selection is inside the &lt;CODE&gt;where&lt;/CODE&gt; clause, Is there a way to do conditional selection outside the &lt;CODE&gt;where&lt;/CODE&gt; clause, meaning if I did not select cityCode, the &lt;CODE&gt;where&lt;/CODE&gt; clause should be ignored completely.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 15:22:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-a-conditional-where-based-on-the-field-existence/m-p/482780#M135224</guid>
      <dc:creator>jieli</dc:creator>
      <dc:date>2020-04-24T15:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a conditional where based on the field existence?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-a-conditional-where-based-on-the-field-existence/m-p/482781#M135225</link>
      <description>&lt;P&gt;hi @jieli,&lt;/P&gt;

&lt;P&gt;Try this. Here &lt;STRONG&gt;pcc&lt;/STRONG&gt; will be set to "" values when &lt;STRONG&gt;cityCode&lt;/STRONG&gt; not exists in the events and &lt;CODE&gt;like&lt;/CODE&gt; matches "" values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mvexpand metrics | spath input=metrics | eval pcc = if(isnotnull(cityCode), cityCode, "") | where if($selected_pcc|s$="all",like(pcc,"%"),like(pcc,$selected_pcc|s$)) | stats count as Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 16:29:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-a-conditional-where-based-on-the-field-existence/m-p/482781#M135225</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-04-24T16:29:41Z</dc:date>
    </item>
  </channel>
</rss>

