<?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 do I also include the values which has stats count 0 in the table ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371518#M109322</link>
    <description>&lt;P&gt;You need source for a canonical list of "all the XYZ things".  For simplicity, let's not use &lt;CODE&gt;xyz&lt;/CODE&gt; but rather &lt;CODE&gt;host&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Let's assume you have the canonical list in a set of tags, then you can use this search to obtain it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rest/servicesNS/-/-/configs/conf-tags 
| search YourTagNameHere=enabled 
| fields title 
| rex field=title mode=sed "s/host=//" 
| rename title AS host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let's assume it is in a CSV, then you can use this search to obtain it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv MyCSV | table host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In any case, once you have the search that generated the canonical list of hosts, you can do a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR DATA SEARCH HERE
| append [YOUR SEARCH FOR CANONICAL LIST HERE] 
| stats values(*) AS * BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You might start with a &lt;CODE&gt;tstats&lt;/CODE&gt; search because it is so much more efficient:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count where index=_* OR index=* BY host sourcetype index 
| append [YOUR SEARCH FOR CANONICAL LIST HERE] 
| stats values(*) AS * BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Be aware that if you are doing &lt;CODE&gt;stats count&lt;/CODE&gt; instead of &lt;CODE&gt;stats count(something)&lt;/CODE&gt; you will have to do this at the end to get rid of the added non-data list:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval count = count - 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Mar 2017 15:02:32 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-03-23T15:02:32Z</dc:date>
    <item>
      <title>How do I also include the values which has stats count 0 in the table ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371516#M109320</link>
      <description>&lt;P&gt;I'm trying to get the usage of some values (say, xyz)  by "stats count by xyz" where i am getting the results of xyz which has count greater than 0 like,&lt;BR /&gt;
xyz     |   count &lt;BR /&gt;
nasj    |     10&lt;BR /&gt;
asjn    |     40&lt;BR /&gt;
asjd    |     23&lt;/P&gt;

&lt;P&gt;but i m also pretty sure where some values of xyz also has count 0. how do i get that ? should be like,&lt;BR /&gt;
xyz     |   count &lt;BR /&gt;
nasj    |     10&lt;BR /&gt;
asjn    |     40&lt;BR /&gt;
asjd    |     23&lt;BR /&gt;
ansj    |     0&lt;BR /&gt;
sfdn    |    0&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 13:05:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371516#M109320</guid>
      <dc:creator>shaal89</dc:creator>
      <dc:date>2017-03-23T13:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I also include the values which has stats count 0 in the table ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371517#M109321</link>
      <description>&lt;P&gt;One way to do this is if you pull, from somewhere, a list of all the values of xyz that you always want on the list.  Then, you use sum() on a field with either a one (selected records) or a zero (all values to report) and it looks like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...your search that gets all xyz records you want to count...
| table xyz | eval mycount=1
| append [...your search that gets ALL xyz values that you want to report... | table xyz | eval mycount=0]
| stats sum(mycount) as count by xyz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So, here's a run-anywhere code sample demonstrating the technique with your fake data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval xyz="nasj nasj nasj nasj nasj nasj nasj nasj nasj nasj asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjn asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd asjd" 
| makemv xyz 
| mvexpand xyz

| table xyz | eval mycount=1
| append 
    [| makeresults | eval xyz="nasj asjn asjd ansj sfdn" | makemv xyz | mvexpand xyz
     | table xyz | eval mycount=0]
| stats sum(mycount) as count by xyz
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 14:29:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371517#M109321</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-23T14:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I also include the values which has stats count 0 in the table ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371518#M109322</link>
      <description>&lt;P&gt;You need source for a canonical list of "all the XYZ things".  For simplicity, let's not use &lt;CODE&gt;xyz&lt;/CODE&gt; but rather &lt;CODE&gt;host&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Let's assume you have the canonical list in a set of tags, then you can use this search to obtain it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rest/servicesNS/-/-/configs/conf-tags 
| search YourTagNameHere=enabled 
| fields title 
| rex field=title mode=sed "s/host=//" 
| rename title AS host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let's assume it is in a CSV, then you can use this search to obtain it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv MyCSV | table host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In any case, once you have the search that generated the canonical list of hosts, you can do a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR DATA SEARCH HERE
| append [YOUR SEARCH FOR CANONICAL LIST HERE] 
| stats values(*) AS * BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You might start with a &lt;CODE&gt;tstats&lt;/CODE&gt; search because it is so much more efficient:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count where index=_* OR index=* BY host sourcetype index 
| append [YOUR SEARCH FOR CANONICAL LIST HERE] 
| stats values(*) AS * BY host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Be aware that if you are doing &lt;CODE&gt;stats count&lt;/CODE&gt; instead of &lt;CODE&gt;stats count(something)&lt;/CODE&gt; you will have to do this at the end to get rid of the added non-data list:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval count = count - 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:02:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-also-include-the-values-which-has-stats-count-0-in-the/m-p/371518#M109322</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-23T15:02:32Z</dc:date>
    </item>
  </channel>
</rss>

