<?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 you order stats by multiple hierarchical fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268481#M80754</link>
    <description>&lt;P&gt;This should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=events 
| stats count(type) as tcount ,count(subtype) as scount by type,subtype
| stats sum(tcount) as "Type Count" list(scount) as "Subtype Count" list(subtype) as "Subtype" by type
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Feb 2016 21:54:04 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2016-02-03T21:54:04Z</dc:date>
    <item>
      <title>How do you order stats by multiple hierarchical fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268480#M80753</link>
      <description>&lt;P&gt;There are similar questions to this, but none are quite the same so I apologize for the overlap.&lt;/P&gt;

&lt;P&gt;Suppose I have a set of data (events) that have a type and a subtype.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;type = A, subtype = A1, A2, A3
type = B, subtype = B1, B2
type = C, subtype = (empty list)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So the events might look like this in time order:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;event 1, type = C, ...
event 2, type = A, subtype=A3, ...
event 3, type = A, subtype=A1, ...
event 4, type = B, subtype=B2, ...
event 5, etc...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've done searches similar to the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=events | stats count(type),count(subtype) by type,subtype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But those results do not exhibit the desired grouping.   I would like for the resulting table to look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;type | count(type) | subtype | count(subtype)
A           2           A1            1
                        A2            1
B           1           B1            1
C           1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 20:20:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268480#M80753</guid>
      <dc:creator>mbintz</dc:creator>
      <dc:date>2016-02-03T20:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do you order stats by multiple hierarchical fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268481#M80754</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=events 
| stats count(type) as tcount ,count(subtype) as scount by type,subtype
| stats sum(tcount) as "Type Count" list(scount) as "Subtype Count" list(subtype) as "Subtype" by type
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 21:54:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268481#M80754</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-02-03T21:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you order stats by multiple hierarchical fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268482#M80755</link>
      <description>&lt;P&gt;Probably throw a fillnull for subtype before first stats, as it can be null/empty and stats will ignore the type without a subtype.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2016 22:40:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-order-stats-by-multiple-hierarchical-fields/m-p/268482#M80755</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-03T22:40:26Z</dc:date>
    </item>
  </channel>
</rss>

