<?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 include counts with 0 events? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473607#M133244</link>
    <description>&lt;P&gt;Another way to do this I just learned from my own Splunk Answers question is the method of |stats count(eval(condition)) as countName. Try this search out and see if it works for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" sourcetype=source1 OR sourcetype=source2 
| stats count(eval(sourcetype=source1)) AS "Number of Source 1 Events", count(eval(sourcetype=source2)) AS "Source2 Events"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I used different "AS" formats to help breakdown the search - that way you can see what has changed and modify on your own. Anyway, this will add to your total only if the eval condition is true. The inner eval condition could just as easily be EventCode=4624 or anything else you'd like to count - the as is just formatting. &lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2019 21:57:51 GMT</pubDate>
    <dc:creator>danielransell</dc:creator>
    <dc:date>2019-11-04T21:57:51Z</dc:date>
    <item>
      <title>How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473601#M133238</link>
      <description>&lt;P&gt;Stats count is not showing me the number of counts if there are no events for the particular search. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" AND (sourctype="source1" OR sourcetype="source2") | stats count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result is showing me:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype: source1
count: 34
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it is not showing anything for source2 since there are no events for that source. &lt;BR /&gt;
Below is how I want the result to show:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype:  source1                                       count: 34
 sourcetype:  source2                                       count: 0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2019 21:11:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473601#M133238</guid>
      <dc:creator>eliassplunk</dc:creator>
      <dc:date>2019-11-01T21:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473602#M133239</link>
      <description>&lt;P&gt;If there are no events for the source, they won't be in the results. If you must show a count always, you can do this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" AND (sourctype="source1" OR sourcetype="source2") 
| stats count as total by sourcetype
|append 
  [|makeresults 
  | eval sourcetype=mvappend("source1", "source2")
  | mvexpand sourcetype
  | eval total=0]
|stats max(total) as total by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 21:19:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473602#M133239</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-01T21:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473603#M133240</link>
      <description>&lt;P&gt;Thank you for your help. I was stuck all day trying to do this. &lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 21:27:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473603#M133240</guid>
      <dc:creator>eliassplunk</dc:creator>
      <dc:date>2019-11-01T21:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473604#M133241</link>
      <description>&lt;P&gt;Try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" AND (sourctype="source1" OR sourcetype="source2") 
| stats count by sourcetype 
| append 
    [| stats count 
    | eval sourcetype=split("source1,source2",",") 
    | mvexpand sourcetype] 
| stats sum(count) as count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2019 21:27:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473604#M133241</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-11-01T21:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473605#M133242</link>
      <description>&lt;P&gt;I'm seeing an issue with the answer. It's pretty 0 no matter what even where there are events for source 2 instead of showing the number of events. &lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 21:47:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473605#M133242</guid>
      <dc:creator>eliassplunk</dc:creator>
      <dc:date>2019-11-01T21:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473606#M133243</link>
      <description>&lt;P&gt;That's strange. Can you check if there are no typos on the field names?&lt;/P&gt;

&lt;P&gt;As a test, I tried this on the internal index and it works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd OR sourcetype=splunkd2 
| stats count as total by sourcetype 
| append 
    [| makeresults 
    | eval sourcetype=mvappend("splunkd", "splunkd2") 
    | mvexpand sourcetype 
    | eval total=0] 
| stats max(total) as total by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can you paste this exact query and check if it works ?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 23:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473606#M133243</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-01T23:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473607#M133244</link>
      <description>&lt;P&gt;Another way to do this I just learned from my own Splunk Answers question is the method of |stats count(eval(condition)) as countName. Try this search out and see if it works for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" sourcetype=source1 OR sourcetype=source2 
| stats count(eval(sourcetype=source1)) AS "Number of Source 1 Events", count(eval(sourcetype=source2)) AS "Source2 Events"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I used different "AS" formats to help breakdown the search - that way you can see what has changed and modify on your own. Anyway, this will add to your total only if the eval condition is true. The inner eval condition could just as easily be EventCode=4624 or anything else you'd like to count - the as is just formatting. &lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 21:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473607#M133244</guid>
      <dc:creator>danielransell</dc:creator>
      <dc:date>2019-11-04T21:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473608#M133245</link>
      <description>&lt;P&gt;I just answered this here:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/781448/how-to-group-by-forcing-line-value.html#answer-780753"&gt;https://answers.splunk.com/answers/781448/how-to-group-by-forcing-line-value.html#answer-780753&lt;/A&gt;&lt;BR /&gt;
So like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" AND (sourctype="source1" OR sourcetype="source2")
| append [|makeresults
| rename COMMENT AS "This would better be done using a 'lookup' file with ' |inputlookup append=t' instead of '|makeresults ...'"
| eval sourcetype="source1 source2 list all possible values here"
| makemv sourcetype ]
| stats count(host) AS count BY sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Nov 2019 05:39:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473608#M133245</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-05T05:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to include counts with 0 events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473609#M133246</link>
      <description>&lt;P&gt;Thank you for your help! This worked great!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 21:25:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-counts-with-0-events/m-p/473609#M133246</guid>
      <dc:creator>eliassplunk</dc:creator>
      <dc:date>2019-11-20T21:25:03Z</dc:date>
    </item>
  </channel>
</rss>

