<?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 search multiple counts based on fields condition using single stat in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487824#M136290</link>
    <description>&lt;P&gt;Hi @avni26 &lt;/P&gt;

&lt;P&gt;This rightly does not work and here's why.&lt;/P&gt;

&lt;P&gt;The first two commands albeit looking through multiple field values returns one single aggregated value whereas the values is expected to return one single multi value field of restore_duration values for Sev1 scenarios.&lt;/P&gt;

&lt;P&gt;The below run anywhere example should work for you by virtue of creating the additional duration field. You should be able to customize it to work for your example. If you need to create a multivalue field(which is a complication), use streamstats to create a field based on severity ahead of your stats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=10 
| streamstats count
| eval status=if(count%2&amp;gt;0,"true","false") , severity=if(count%2&amp;gt;0,2,1),restore_duration=if(count%2&amp;gt;0,25,30), duration=if(severity=1,restore_duration,null())
| stats count as total_count count(eval(status="true")) as status_count avg(duration) as duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Sep 2019 15:29:15 GMT</pubDate>
    <dc:creator>vik_splunk</dc:creator>
    <dc:date>2019-09-19T15:29:15Z</dc:date>
    <item>
      <title>How to search multiple counts based on fields condition using single stat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487822#M136288</link>
      <description>&lt;P&gt;There are multiple fields like &lt;BR /&gt;
time number description severity status restore_duration&lt;BR /&gt;
I want to take total count , count when status has true value , values  of  restore_duration when severity is 1.&lt;BR /&gt;
I am trying with stats command like below, but for 3rd requirement its not working&lt;/P&gt;

&lt;P&gt;| stats count as total_count count(eval(status="true")) as status_count values(eval(if(severity="1",restore_duration,null))) as duration &lt;/P&gt;

&lt;P&gt;Please suggest, how to achieve when severity=1, then get the values of restore_duration using same stats.&lt;BR /&gt;
After taking values from restore_duration , i have to calculate average of duration also.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:18:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487822#M136288</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2020-09-30T02:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to search multiple counts based on fields condition using single stat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487823#M136289</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Instead putting the if condition in stats , have the eval if condition before stats sepatly and try &lt;/P&gt;

&lt;P&gt;|eval duration=if((severity="1"),restore_duration,null)&lt;BR /&gt;
| stats count as total_count,  count(eval(status="true")) as status_count&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487823#M136289</guid>
      <dc:creator>Anantha123</dc:creator>
      <dc:date>2020-09-30T02:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to search multiple counts based on fields condition using single stat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487824#M136290</link>
      <description>&lt;P&gt;Hi @avni26 &lt;/P&gt;

&lt;P&gt;This rightly does not work and here's why.&lt;/P&gt;

&lt;P&gt;The first two commands albeit looking through multiple field values returns one single aggregated value whereas the values is expected to return one single multi value field of restore_duration values for Sev1 scenarios.&lt;/P&gt;

&lt;P&gt;The below run anywhere example should work for you by virtue of creating the additional duration field. You should be able to customize it to work for your example. If you need to create a multivalue field(which is a complication), use streamstats to create a field based on severity ahead of your stats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=10 
| streamstats count
| eval status=if(count%2&amp;gt;0,"true","false") , severity=if(count%2&amp;gt;0,2,1),restore_duration=if(count%2&amp;gt;0,25,30), duration=if(severity=1,restore_duration,null())
| stats count as total_count count(eval(status="true")) as status_count avg(duration) as duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 15:29:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487824#M136290</guid>
      <dc:creator>vik_splunk</dc:creator>
      <dc:date>2019-09-19T15:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to search multiple counts based on fields condition using single stat</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487825#M136291</link>
      <description>&lt;P&gt;@Anantha123 Thank you. It perfectly worked for me&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 16:55:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-multiple-counts-based-on-fields-condition-using/m-p/487825#M136291</guid>
      <dc:creator>avni26</dc:creator>
      <dc:date>2019-09-19T16:55:52Z</dc:date>
    </item>
  </channel>
</rss>

