<?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: stats count include zero in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708230#M239510</link>
    <description>&lt;P&gt;No. Your understanding is wrong. At each step of the search pipeline Splunk only has the data from the previous step in the pipe. So when you filter your data with | search, it onky retains the results matched by your command.&lt;/P&gt;&lt;P&gt;The data from before that command is no longer there so stats cannot use it to group by. So how should it know what are the possible values? Splunk cannot find what is not there so it cannot generate a zero result for a potential non-existing by-field value because it doesn't know what value that would be.&lt;/P&gt;&lt;P&gt;The only case when stats do return a zero value is when you do an overall stats count and you have no results at all.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2025 05:06:40 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2025-01-08T05:06:40Z</dc:date>
    <item>
      <title>stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708195#M239496</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;First, I am aware that there are multiple posts regarding my question, but I can't seem to use them in my scenario.&lt;BR /&gt;Please see an example below. There are two fields, location and name. I need to filter out name that contain&amp;nbsp; "2" and &lt;STRONG&gt;stats count&lt;/STRONG&gt; name based on location.&amp;nbsp;&lt;BR /&gt;I came up with this search, but the problem is it did not include location A (because the count is zero)&lt;BR /&gt;Please suggest. I appreciate your help.&amp;nbsp; Thanks&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="location,	name
location A,	name A2
location B,	name B1
location B,	name B2
location C,	name C1
location C,	name C2 
location C,	name C3"
| search name != "*2*"
| stats count by location&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE width="201"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="90"&gt;&lt;STRONG&gt;location&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="111"&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location A&lt;/TD&gt;&lt;TD&gt;name A2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location B&lt;/TD&gt;&lt;TD&gt;name B1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location B&lt;/TD&gt;&lt;TD&gt;name B2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location C&lt;/TD&gt;&lt;TD&gt;name C1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location C&lt;/TD&gt;&lt;TD&gt;name C2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location C&lt;/TD&gt;&lt;TD&gt;name C3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected output:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE width="201"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="90"&gt;&lt;STRONG&gt;location&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="111"&gt;&lt;STRONG&gt;count(name)&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location A&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;location C&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 07 Jan 2025 18:46:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708195#M239496</guid>
      <dc:creator>LearningGuy</dc:creator>
      <dc:date>2025-01-07T18:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708206#M239500</link>
      <description>&lt;P&gt;This is the typical "proving the negative" case. &lt;A href="https://www.duanewaddle.com/proving-a-negative/" target="_blank"&gt;https://www.duanewaddle.com/proving-a-negative/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Append (from a lookup or a here-document), sum and you're set.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 20:02:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708206#M239500</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-01-07T20:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708216#M239505</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;Is there any other way to do this?&lt;BR /&gt;The data is dynamic. If I am doing this way, I have to have another process to dump a CSV file.&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 21:28:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708216#M239505</guid>
      <dc:creator>LearningGuy</dc:creator>
      <dc:date>2025-01-07T21:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708221#M239508</link>
      <description>&lt;P&gt;And how is Splunk supposed to know that there should be something there if there isn't? You have to tell it somehow.&lt;/P&gt;&lt;P&gt;If you know that there is alway something with the 2 at the end and it is to be the base of your count, that's a completely different use case and can be done by some groupping and filtering.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 21:48:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708221#M239508</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-01-07T21:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708222#M239509</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;My understanding is the data is there somewhere, Splunk decided to not display 0 when using stats count.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 22:58:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708222#M239509</guid>
      <dc:creator>LearningGuy</dc:creator>
      <dc:date>2025-01-07T22:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708230#M239510</link>
      <description>&lt;P&gt;No. Your understanding is wrong. At each step of the search pipeline Splunk only has the data from the previous step in the pipe. So when you filter your data with | search, it onky retains the results matched by your command.&lt;/P&gt;&lt;P&gt;The data from before that command is no longer there so stats cannot use it to group by. So how should it know what are the possible values? Splunk cannot find what is not there so it cannot generate a zero result for a potential non-existing by-field value because it doesn't know what value that would be.&lt;/P&gt;&lt;P&gt;The only case when stats do return a zero value is when you do an overall stats count and you have no results at all.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 05:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708230#M239510</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-01-08T05:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: stats count include zero</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708282#M239530</link>
      <description>&lt;P&gt;One way to do it is this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="location,	name
location A,	name A2
location B,	name B1
location B,	name B2
location C,	name C1
location C,	name C2 
location C,	name C3" 
| search name != "*2*" 
| stats count by location 
| append 
    [| makeresults format=csv data="location,	name
location A,	name A2
location B,	name B1
location B,	name B2
location C,	name C1
location C,	name C2 
location C,	name C3" 
    | eval count=0 
    | fields location count 
    | dedup location] 
| stats sum by location&lt;/LI-CODE&gt;&lt;P&gt;but as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;said, Splunk is not good with non existent values.&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 18:08:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-count-include-zero/m-p/708282#M239530</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2025-01-08T18:08:18Z</dc:date>
    </item>
  </channel>
</rss>

