<?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 Add 0 Count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47744#M11393</link>
    <description>&lt;P&gt;Need some help adding a 0 count at search time.&lt;/P&gt;

&lt;P&gt;I have a log that contains the execution duration of a code function.&lt;BR /&gt;
Using stats I can count the number of times the function took&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
 |stats count by functionDuration&lt;/P&gt;

&lt;P&gt;functionDuration|count&lt;BR /&gt;&lt;BR /&gt;
120|1&lt;BR /&gt;&lt;BR /&gt;
122|2&lt;BR /&gt;&lt;BR /&gt;
123|1&lt;BR /&gt;&lt;BR /&gt;
124|5&lt;BR /&gt;&lt;BR /&gt;
130|10&lt;BR /&gt;&lt;BR /&gt;
132|8&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
From this the functionDuration took 120 1 time, 122 2 times, etc...&lt;/P&gt;

&lt;P&gt;I would like to show a count of 0 for the missing functionDuration times.&lt;/P&gt;

&lt;P&gt;functionDuration|count&lt;BR /&gt;&lt;BR /&gt;
120|1&lt;BR /&gt;&lt;BR /&gt;
121|0&lt;BR /&gt;&lt;BR /&gt;
122|2&lt;BR /&gt;&lt;BR /&gt;
123|1&lt;BR /&gt;&lt;BR /&gt;
124|5&lt;BR /&gt;&lt;BR /&gt;
125|0&lt;BR /&gt;&lt;BR /&gt;
126|0&lt;BR /&gt;&lt;BR /&gt;
127|0&lt;BR /&gt;&lt;BR /&gt;
128|0&lt;BR /&gt;&lt;BR /&gt;
129|0&lt;BR /&gt;&lt;BR /&gt;
130|10&lt;BR /&gt;&lt;BR /&gt;
131|0&lt;BR /&gt;&lt;BR /&gt;
132|8&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I searched around and couldn't find answer.&lt;BR /&gt;
Thanks for any help.&lt;/P&gt;</description>
    <pubDate>Thu, 10 May 2012 01:36:33 GMT</pubDate>
    <dc:creator>johnmca</dc:creator>
    <dc:date>2012-05-10T01:36:33Z</dc:date>
    <item>
      <title>Add 0 Count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47744#M11393</link>
      <description>&lt;P&gt;Need some help adding a 0 count at search time.&lt;/P&gt;

&lt;P&gt;I have a log that contains the execution duration of a code function.&lt;BR /&gt;
Using stats I can count the number of times the function took&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
 |stats count by functionDuration&lt;/P&gt;

&lt;P&gt;functionDuration|count&lt;BR /&gt;&lt;BR /&gt;
120|1&lt;BR /&gt;&lt;BR /&gt;
122|2&lt;BR /&gt;&lt;BR /&gt;
123|1&lt;BR /&gt;&lt;BR /&gt;
124|5&lt;BR /&gt;&lt;BR /&gt;
130|10&lt;BR /&gt;&lt;BR /&gt;
132|8&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
From this the functionDuration took 120 1 time, 122 2 times, etc...&lt;/P&gt;

&lt;P&gt;I would like to show a count of 0 for the missing functionDuration times.&lt;/P&gt;

&lt;P&gt;functionDuration|count&lt;BR /&gt;&lt;BR /&gt;
120|1&lt;BR /&gt;&lt;BR /&gt;
121|0&lt;BR /&gt;&lt;BR /&gt;
122|2&lt;BR /&gt;&lt;BR /&gt;
123|1&lt;BR /&gt;&lt;BR /&gt;
124|5&lt;BR /&gt;&lt;BR /&gt;
125|0&lt;BR /&gt;&lt;BR /&gt;
126|0&lt;BR /&gt;&lt;BR /&gt;
127|0&lt;BR /&gt;&lt;BR /&gt;
128|0&lt;BR /&gt;&lt;BR /&gt;
129|0&lt;BR /&gt;&lt;BR /&gt;
130|10&lt;BR /&gt;&lt;BR /&gt;
131|0&lt;BR /&gt;&lt;BR /&gt;
132|8&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I searched around and couldn't find answer.&lt;BR /&gt;
Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2012 01:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47744#M11393</guid>
      <dc:creator>johnmca</dc:creator>
      <dc:date>2012-05-10T01:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add 0 Count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47745#M11394</link>
      <description>&lt;P&gt;Maybe this one could help with some inspiration? &lt;A href="http://splunk-base.splunk.com/answers/23839/include-zero-count-in-stats-count"&gt;http://splunk-base.splunk.com/answers/23839/include-zero-count-in-stats-count&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2012 21:56:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47745#M11394</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-05-10T21:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add 0 Count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47746#M11395</link>
      <description>&lt;P&gt;It would be nice if you could just have a command called like &lt;CODE&gt;generateRows rows=N&lt;/CODE&gt; that would generate a result set with N rows.   &lt;/P&gt;

&lt;P&gt;However we can hack one together ourselves using a search for the 1000 most recent events in the last 30 days. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;search terms&amp;gt; | stats count by functionDuration | append [| search index=* OR index=_internal earliest=-30d | head 1000 | fields - * | fields - _* | streamstats count | rename count as functionDuration | eval count=0] | stats sum(count) as count by functionDuration | sort functionDuration&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The basic idea is,  use our weird subsearch hack to append 1000 rows,  with every functionDuration value from 1-1000 represented.   Then when we wash the original "real" events together with the fake events,  through `| stats sum(count) as count by functionDuration),  suddenly we'll have every functionDuration value from 1-1000 represented... &lt;/P&gt;

&lt;P&gt;Alternates: &lt;BR /&gt;
1) Instead of the weird &lt;CODE&gt;index=* OR index=_*&lt;/CODE&gt; search, you could also just use a csv in /var/run/dispatch that has 1000 rows in it.&lt;BR /&gt;&lt;BR /&gt;
2) Or you could do the trick in that other answer,  where you do &lt;CODE&gt;| eval foo="1,2,3,4,5,6,7,8,..." | eval foo=split(foo,",") | mvexpand foo&lt;/CODE&gt;,  but I'm not sure those commands will be overjoyed at expanding out to thousands of rows...   You might hit a limit around 100 or a couple hundred. &lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2012 00:01:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47746#M11395</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2012-05-11T00:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Add 0 Count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47747#M11396</link>
      <description>&lt;P&gt;Thanks - this worked great to fill in all the 0 for my missing values.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 05:25:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-0-Count/m-p/47747#M11396</guid>
      <dc:creator>the_wolverine</dc:creator>
      <dc:date>2014-01-14T05:25:20Z</dc:date>
    </item>
  </channel>
</rss>

