<?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: Search Top Field If exists in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-Top-Field-If-exists/m-p/181431#M52297</link>
    <description>&lt;P&gt;Couple of things. First of all, welcome &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Then, &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Eval"&gt;eval&lt;/A&gt;. You need to specify a field where your &lt;CODE&gt;eval&lt;/CODE&gt; can put its content, so a typical command looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval check=if(1=1,"world_ok","problems")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which would give you a new field called "check" which should always show you that the world is ok.&lt;/P&gt;

&lt;P&gt;Also, you don't use if like you do in a programming language; see &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;here&lt;/A&gt; for how it works (it's related to how &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Eval"&gt;eval&lt;/A&gt; works). If you want different behavior based on the number of results a search has, you'll ned to do that another way, for example in Javascript (since you're on a dashboard). In your case, an easy solution could be to calculate and show both statistics separately (the one about the &lt;CODE&gt;top exception_type&lt;/CODE&gt; returning nothing to see sometimes).&lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2015 11:45:16 GMT</pubDate>
    <dc:creator>jeffland</dc:creator>
    <dc:date>2015-05-06T11:45:16Z</dc:date>
    <item>
      <title>Search Top Field If exists</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Top-Field-If-exists/m-p/181430#M52296</link>
      <description>&lt;P&gt;I'm very new to Splunk, and I'm trying to figure out a way to search by different top fields, depending on whether the first field exists or is not null.  Let me try to explain...  I have some data that comes in with different severities, and I've created an Extracted Field for an exception_type.  The exception_type is only set on rows with a severity of WARN or ERROR.&lt;/P&gt;

&lt;P&gt;I'm trying to create a dashboard that I can filter using a dropdown by severity, and it will show a chart of counts of events broken down by exception type.  If there are no exception types for that severity, I just want to show an overall count.  I started with this, and obviously it doesn't work, but it might give an indication of what I'm trying to do:&lt;/P&gt;

&lt;P&gt;severity=$severity$ | eval if(isnotnull(exception_type),top exception_type,stats count as Total) showperc=0&lt;/P&gt;

&lt;P&gt;Using "severity=$severity$ | top exception_type showperc=0", and selecting my DD, I get results for WARN and ERROR, but other severities show nothing.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/35852-warn.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/35853-debug.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Thanks, I appreciate any help you can give! - Mark&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:50:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Top-Field-If-exists/m-p/181430#M52296</guid>
      <dc:creator>MDClayton</dc:creator>
      <dc:date>2020-09-28T19:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Search Top Field If exists</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Top-Field-If-exists/m-p/181431#M52297</link>
      <description>&lt;P&gt;Couple of things. First of all, welcome &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Then, &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Eval"&gt;eval&lt;/A&gt;. You need to specify a field where your &lt;CODE&gt;eval&lt;/CODE&gt; can put its content, so a typical command looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval check=if(1=1,"world_ok","problems")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which would give you a new field called "check" which should always show you that the world is ok.&lt;/P&gt;

&lt;P&gt;Also, you don't use if like you do in a programming language; see &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;here&lt;/A&gt; for how it works (it's related to how &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Eval"&gt;eval&lt;/A&gt; works). If you want different behavior based on the number of results a search has, you'll ned to do that another way, for example in Javascript (since you're on a dashboard). In your case, an easy solution could be to calculate and show both statistics separately (the one about the &lt;CODE&gt;top exception_type&lt;/CODE&gt; returning nothing to see sometimes).&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 11:45:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Top-Field-If-exists/m-p/181431#M52297</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-05-06T11:45:16Z</dc:date>
    </item>
  </channel>
</rss>

