<?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 How to write a search to display a table of counts, including fields with 0 results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217017#M63725</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;How can I create this kind of table?&lt;/P&gt;

&lt;P&gt;MissingA :          0&lt;BR /&gt;
MissingB :          100&lt;BR /&gt;
MissingC :          200&lt;/P&gt;

&lt;P&gt;I'd like to create a dashboard that has rows for MissingA, MissingB and MissingC.  These row values are static, meaning that I search my logs for this data and if it's available, I can do a count.  I've tried some evals/stats, but I can't get it to display the MissingA (because the count is 0, this row disappears instead of displaying as 0).  Do you know how I could create this table?    &lt;/P&gt;

&lt;P&gt;Here are some sample records:&lt;BR /&gt;
type=MissingC msg="Data is missing for type1"&lt;BR /&gt;
type=MissingC msg="Data is missing for type1"&lt;BR /&gt;
type=MissingD msg="Data is missing for type500"&lt;BR /&gt;
type=MissingD msg="Data is missing for type500"&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2016 23:45:33 GMT</pubDate>
    <dc:creator>ceng</dc:creator>
    <dc:date>2016-02-23T23:45:33Z</dc:date>
    <item>
      <title>How to write a search to display a table of counts, including fields with 0 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217017#M63725</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;How can I create this kind of table?&lt;/P&gt;

&lt;P&gt;MissingA :          0&lt;BR /&gt;
MissingB :          100&lt;BR /&gt;
MissingC :          200&lt;/P&gt;

&lt;P&gt;I'd like to create a dashboard that has rows for MissingA, MissingB and MissingC.  These row values are static, meaning that I search my logs for this data and if it's available, I can do a count.  I've tried some evals/stats, but I can't get it to display the MissingA (because the count is 0, this row disappears instead of displaying as 0).  Do you know how I could create this table?    &lt;/P&gt;

&lt;P&gt;Here are some sample records:&lt;BR /&gt;
type=MissingC msg="Data is missing for type1"&lt;BR /&gt;
type=MissingC msg="Data is missing for type1"&lt;BR /&gt;
type=MissingD msg="Data is missing for type500"&lt;BR /&gt;
type=MissingD msg="Data is missing for type500"&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217017#M63725</guid>
      <dc:creator>ceng</dc:creator>
      <dc:date>2016-02-23T23:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to display a table of counts, including fields with 0 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217018#M63726</link>
      <description>&lt;P&gt;I've found a similar answer that can do it -- &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Query:&lt;/STRONG&gt; &lt;BR /&gt;
source="WinEventLog:" | stats count by EventType | append [| stats count | eval EventType=split("1,2,3,4,5",",") | mvexpand EventType] | stats sum(count) as count by EventType&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/229049/display-a-result-when-the-count-0.html"&gt;https://answers.splunk.com/answers/229049/display-a-result-when-the-count-0.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 00:30:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217018#M63726</guid>
      <dc:creator>ceng</dc:creator>
      <dc:date>2016-02-24T00:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to display a table of counts, including fields with 0 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217019#M63727</link>
      <description>&lt;P&gt;One way is to let &lt;CODE&gt;stats count by type&lt;/CODE&gt; build the potentially incomplete set,  then append a set of "dummy" rows on the end where each row has a count of "0",  then do a &lt;CODE&gt;stats sum(count) as count&lt;/CODE&gt; at the end. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;&amp;lt;your search terms here&amp;gt;&amp;gt;  
| stats count by type 
| append [| stats count | fields - count | eval type=split("MissingA,MissingB,MissingC,MissingD",",") | mvexpand type | eval count=0]
| stats sum(count) as count by type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give a table that looks like this, and that includes "0" rows even when the given type is missing entirely from the raw data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;------------------------------------
|    type         |    count       |
|   MissingA      |    12          |
|   MissingB      |     0          |
|   MissingC      |    3           |
|   MissingD      |    0           |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;There's another way that you might find easier, or that you might find interesting. That's to create a "chart style" set of output rows first, use a simple fillnull command to add your "0" entries if they're missing (instead of that append command), then use &lt;CODE&gt;untable&lt;/CODE&gt; to turn the "chart style" output into "stats style" rows like the above. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;&amp;lt;your search terms here&amp;gt;&amp;gt;  
| eval foo="1"
| chart count over foo by type 
| fillnull MissingA MissingB MissingC MissingD value="0"
| fields - NULL
| untable foo type count 
| fields - foo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The benefit of this approach is that there's no append.  If you have moral/ethical/religious objections to append (not unreasonable), then this approach may be preferred!&lt;BR /&gt;
Admittedly the little "foo" trick is clunky and funny looking.  untable and xyseries don't have a way of working with only 2 fields so as a workaround you have to give it a dummy third field and then take it away at the end. &lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 00:55:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217019#M63727</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2016-02-24T00:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to display a table of counts, including fields with 0 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217020#M63728</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I saved the following  record in missing.txt file  and indexed it in my splunk 6.3.2 instance&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;type=MissingC msg="Data is missing for type1"
type=MissingC msg="Data is missing for type1"
type=MissingD msg="Data is missing for type500"
type=MissingD msg="Data is missing for type500"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then i perfomed the following search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="missing.txt" sourcetype="missing"|rex max_match=0 field=_raw "type\=(?&amp;lt;Missing_field&amp;gt;[^\s+]+)"|mvexpand Missing_field|stats count(_raw) as count by Missing_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;look at the result&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1079i4E075B7B4EB2DA9B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 10:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217020#M63728</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2016-02-24T10:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to display a table of counts, including fields with 0 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217021#M63729</link>
      <description>&lt;P&gt;This worked, thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2016 17:55:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-display-a-table-of-counts-including/m-p/217021#M63729</guid>
      <dc:creator>ceng</dc:creator>
      <dc:date>2016-02-26T17:55:34Z</dc:date>
    </item>
  </channel>
</rss>

