<?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 add sub totals to a table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317028#M94851</link>
    <description>&lt;P&gt;Suppose I have the following table:&lt;/P&gt;

&lt;P&gt;comonent | count |&lt;/P&gt;

&lt;P&gt;--------------|---------|&lt;BR /&gt;
        a1       |    3      |&lt;BR /&gt;
        a2       |    5      |&lt;BR /&gt;
        a3       |    6      |&lt;BR /&gt;
       b1        |   2      |&lt;/P&gt;

&lt;H2&gt;       b2        |   5      |&lt;/H2&gt;

&lt;P&gt;I would like to add two rows to the table that would represent the sum of all the a's and the b's. In other words, I'd like to create new components called &lt;STRONG&gt;a-total&lt;/STRONG&gt; and &lt;STRONG&gt;b-total&lt;/STRONG&gt; that would contain the sum of all the a components and the b components respectfully, and then add those components to the &lt;STRONG&gt;component&lt;/STRONG&gt; field.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 17:42:47 GMT</pubDate>
    <dc:creator>vshakur</dc:creator>
    <dc:date>2018-01-16T17:42:47Z</dc:date>
    <item>
      <title>How to add sub totals to a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317028#M94851</link>
      <description>&lt;P&gt;Suppose I have the following table:&lt;/P&gt;

&lt;P&gt;comonent | count |&lt;/P&gt;

&lt;P&gt;--------------|---------|&lt;BR /&gt;
        a1       |    3      |&lt;BR /&gt;
        a2       |    5      |&lt;BR /&gt;
        a3       |    6      |&lt;BR /&gt;
       b1        |   2      |&lt;/P&gt;

&lt;H2&gt;       b2        |   5      |&lt;/H2&gt;

&lt;P&gt;I would like to add two rows to the table that would represent the sum of all the a's and the b's. In other words, I'd like to create new components called &lt;STRONG&gt;a-total&lt;/STRONG&gt; and &lt;STRONG&gt;b-total&lt;/STRONG&gt; that would contain the sum of all the a components and the b components respectfully, and then add those components to the &lt;STRONG&gt;component&lt;/STRONG&gt; field.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 17:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317028#M94851</guid>
      <dc:creator>vshakur</dc:creator>
      <dc:date>2018-01-16T17:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to add sub totals to a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317029#M94852</link>
      <description>&lt;P&gt;Here's one way to do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
| appendpipe 
  [ | where match(component, "^a") 
    | stats sum(count) AS count 
    | eval component="a-total" ] 
| appendpipe 
  [ |where match(component, "^b") 
    | stats sum(count) AS count 
    | eval component="b-total" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;appendpipe&lt;/CODE&gt; command allows  you to add some more calculations while preserving the original query results.&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Appendpipe"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Appendpipe&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 17:55:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317029#M94852</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-16T17:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to add sub totals to a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317030#M94853</link>
      <description>&lt;P&gt;If you need to sort as well (giving all a's and corresponding a-total, then all b's and corresponding b-total), try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving fields component and count
| eval keep=0
| appendpipe [| where match(component,"^a") | addcoltotals labelfield=component label="a-total" 
 eval keep=1]
| appendpipe [| where match(component,"^b") | addcoltotals labelfield=component label="b-total" 
 eval keep=1]
| where keep=1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 18:50:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-sub-totals-to-a-table/m-p/317030#M94853</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-16T18:50:15Z</dc:date>
    </item>
  </channel>
</rss>

