<?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 filter search result based on case condition in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362460#M66078</link>
    <description>&lt;P&gt;Thanks a lot! Tried the first query and it worked!&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2017 12:21:15 GMT</pubDate>
    <dc:creator>andreigro</dc:creator>
    <dc:date>2017-05-04T12:21:15Z</dc:date>
    <item>
      <title>How to filter search result based on case condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362458#M66076</link>
      <description>&lt;P&gt;Hi guys, I'm new to splunk and I have one issue with filtering my search results based on a case condition&lt;BR /&gt;
My search string:&lt;BR /&gt;
sourcetype="WMI:CPUTime" | eval selected_host=case("$ddl_instance$" == "a", "Server1", "$ddl_instance$" == "b", "Server2", "$ddl_instance$" == "c", "Server3") | timechart span=1d eval(round(avg(PercentProcessorTime),1)) by host limit=20&lt;/P&gt;

&lt;P&gt;I now I need to filter this based on the field named &lt;STRONG&gt;host&lt;/STRONG&gt;=selected_host&lt;/P&gt;

&lt;P&gt;It doesn't sound very complex but I cannot make it work.&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Andrei&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:56:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362458#M66076</guid>
      <dc:creator>andreigro</dc:creator>
      <dc:date>2020-09-29T13:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter search result based on case condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362459#M66077</link>
      <description>&lt;P&gt;Try one of these.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="WMI:CPUTime" | eval selected_host=case("$ddl_instance$" == "a", "Server1", "$ddl_instance$" == "b", "Server2", "$ddl_instance$" == "c", "Server3") | where host=selected_host | timechart span=1d eval(round(avg(PercentProcessorTime),1)) by host limit=20

sourcetype="WMI:CPUTime" | where host=case("$ddl_instance$" == "a", "Server1", "$ddl_instance$" == "b", "Server2", "$ddl_instance$" == "c", "Server3") | timechart span=1d eval(round(avg(PercentProcessorTime),1)) by host limit=20
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 May 2017 12:18:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362459#M66077</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-05-04T12:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter search result based on case condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362460#M66078</link>
      <description>&lt;P&gt;Thanks a lot! Tried the first query and it worked!&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 12:21:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362460#M66078</guid>
      <dc:creator>andreigro</dc:creator>
      <dc:date>2017-05-04T12:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter search result based on case condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362461#M66079</link>
      <description>&lt;P&gt;May I know how you are setting $ddl_instance$ token? &lt;/P&gt;

&lt;P&gt;It is most likely that eval can be used to set token at the same place for host directly. That way you will be able to add host in your base query hence resulting in filtering required results upfront rather than later. This should improve your search performance. (&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Define_token_filtering_and_formatting"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/tokens#Define_token_filtering_and_formatting&lt;/A&gt;)&lt;/P&gt;

&lt;P&gt;In the current query you can change &lt;STRONG&gt;by host&lt;/STRONG&gt; to &lt;CODE&gt;by selected_host&lt;/CODE&gt; in your timechart command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="WMI:CPUTime" | eval selected_host=case("$ddl_instance$" == "a", "Server1", "$ddl_instance$" == "b", "Server2", "$ddl_instance$" == "c", "Server3") | timechart span=1d eval(round(avg(PercentProcessorTime),1)) by selected_host limit=20
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 May 2017 12:38:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-filter-search-result-based-on-case-condition/m-p/362461#M66079</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-04T12:38:09Z</dc:date>
    </item>
  </channel>
</rss>

