<?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: Count by group subgroup and use subgroup as column in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220535#M64800</link>
    <description>&lt;P&gt;it works well for me. many thanks&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2015 16:29:34 GMT</pubDate>
    <dc:creator>splunknewbieste</dc:creator>
    <dc:date>2015-11-06T16:29:34Z</dc:date>
    <item>
      <title>Count by group subgroup and use subgroup as column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220533#M64798</link>
      <description>&lt;P&gt;I had a query like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;....
| eval group_name = case ( 
    match ( field , "value1" ) , "g1" , 
    match ( field , "value2" ) , "g2" , 
    match ( field , "value2" ) , "g3") 
| spath status 
| stats count by group_name status 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which gives me result like below &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;group_name |  status  | count 
g1         | 200      | x
g1         | 400      | x
g2         | 200      | x
....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I want instead is &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;group_name | 2xx | 3xx | 4xx | 5xx
g1         | x   | x   | x   | x
g2         | x   | x   | x   | x
....               
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I change my query to achieve this?&lt;/P&gt;

&lt;P&gt;Many thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:12:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220533#M64798</guid>
      <dc:creator>splunknewbieste</dc:creator>
      <dc:date>2015-11-06T16:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group subgroup and use subgroup as column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220534#M64799</link>
      <description>&lt;P&gt;replace stats with chart&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | chart count over group_name by status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I generally get the over and by pieces mixed up though so you might have to change that =). Alternatively you could use xyseries after your stats command but that isn't needed with the chart over by (unless you want to sort). Recall that when you use chart the field &lt;CODE&gt;count&lt;/CODE&gt; doesn't exist if you add another piped command.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220534#M64799</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-11-06T16:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group subgroup and use subgroup as column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220535#M64800</link>
      <description>&lt;P&gt;it works well for me. many thanks&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:29:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220535#M64800</guid>
      <dc:creator>splunknewbieste</dc:creator>
      <dc:date>2015-11-06T16:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group subgroup and use subgroup as column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220536#M64801</link>
      <description>&lt;P&gt;@Runals just wonder if it's possible to mix the stats for event that related to &lt;CODE&gt;group_name&lt;/CODE&gt;? For eg, what if I want 2 other columns in that table: (i) &lt;CODE&gt;avg(durationMs)&lt;/CODE&gt; for each group (&lt;CODE&gt;g1, g2, ..&lt;/CODE&gt;) and (ii) &lt;CODE&gt;count&lt;/CODE&gt; for each group?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:57:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220536#M64801</guid>
      <dc:creator>splunknewbieste</dc:creator>
      <dc:date>2015-11-06T16:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group subgroup and use subgroup as column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220537#M64802</link>
      <description>&lt;P&gt;Depending on the volume of data and other factors (ie lazy quotient) I might look at a join but only really if you are looking to get the avg duration per group and not per group and status. My guess is though what you might really want is the avg duration per status code though right? It might look something similar to this which is the avg and max memory usage by system over a series of weeks - assuming the table thing works ok&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host                 | week of 10/04/15  | week of 10/18/15 | etc
system1              avg: 14.5 %                  avg: 21.0 %
                     max: 17.3 %                max: 22.5 %
system2              avg: 64.6%                  avg: 67.1%
                     max: 65.9%                max: 71.0%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If that is the case the query looks like this - at least for my example. You'd need to translate&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="Perfmon:Memory" counter="% Committed Bytes In Use" earliest=-4w@w latest=@w | bin span=1w _time | eval time = "Week of " .strftime(_time, "%m/%d/%y") | eval host=upper(host) | stats avg(Value) as avg max(Value) as max by host time | foreach avg max [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;: " .round(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,1). " %"] | eval val = avg . "|" .max | makemv val delim="|" | xyseries host time val
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The part to pick up on is at the stats command where I'm first getting a line per host and week with the avg and max values. The foreach bit adds the % sign instead of using 2 evals. Then I'm creating a new field to merge the avg and max values BUT with a delimiter to use to turn around and make it a multivalue field (so that the results show up on 2 lines). Then I'm using the xyseries command that I referenced above.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 17:25:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-by-group-subgroup-and-use-subgroup-as-column/m-p/220537#M64802</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-11-06T17:25:52Z</dc:date>
    </item>
  </channel>
</rss>

