<?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 to group rows together in a table and calculate the sum for each group? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278353#M84023</link>
    <description>&lt;P&gt;Little variation of above to give you proper order&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=em7_srm_summary_data srm_units_used&amp;gt;0 | dedup ticket_id | sort cust_name, ticket_id | eval "Closed Date" = if (ticket_date_closed!=0, strftime(ticket_date_closed,"%m/%d/%Y"), "") | stats list("ticket_id") as "Ticket Id", list("Closed Date") as "Closed Date" ,list("srm_units_used") as "SR Units Used" by cust_name | streamstats count as serialno | appendpipe [|stats max(serialno) sum(srm_units_used) as "SR Units Used" by cust_name | eval cust_name=cust_name." Total"] | sort serialno | fields - serialno
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Jun 2016 21:15:56 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-06-02T21:15:56Z</dc:date>
    <item>
      <title>How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278349#M84019</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I need to create table as shown in this screenshot:&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/136194-requirement.jpg" alt="alt text" /&gt;&lt;BR /&gt;
I have written this search for that:&lt;/P&gt;

&lt;P&gt;index=em7_srm_summary_data  srm_units_used&amp;gt;0  | dedup ticket_id | sort cust_name, ticket_id | eval "Closed Date" = if (ticket_date_closed!=0, strftime(ticket_date_closed,"%m/%d/%Y"), "")  |  &lt;STRONG&gt;stats&lt;/STRONG&gt; list("ticket_id") as "Ticket Id", list("Closed Date") as "Closed Date" ,list("srm_units_used") as "SR Units Used" by cust_name | &lt;STRONG&gt;addcoltotals&lt;/STRONG&gt;  "SR Units Used" by cust_name&lt;/P&gt;

&lt;P&gt;I need "SRU Units Used" count for each Customer, but I am not able to get the column total for each Customer using above search. Any idea how to do that?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278349#M84019</guid>
      <dc:creator>asaste</dc:creator>
      <dc:date>2020-09-29T09:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278350#M84020</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=em7_srm_summary_data srm_units_used&amp;gt;0 | dedup ticket_id | sort cust_name, ticket_id | eval "Closed Date" = if (ticket_date_closed!=0, strftime(ticket_date_closed,"%m/%d/%Y"), "") | stats list("ticket_id") as "Ticket Id", list("Closed Date") as "Closed Date" ,list("srm_units_used") as "SR Units Used" by cust_name | appendpipe [|stats sum(srm_units_used) as srm by cust_name | eval cust_name=cust_name." Total"] | sort cust_name
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2016 13:18:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278350#M84020</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-02T13:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278351#M84021</link>
      <description>&lt;P&gt;Thanks a lot for your quick reply. &lt;BR /&gt;
Yes , your query is giving column total for each Customer. But I am not getting column total exactly below customer name. i am getting it in following order. &lt;/P&gt;

&lt;P&gt;Abhi Corp&lt;BR /&gt;
Abhi Corp MSP&lt;BR /&gt;
*&lt;STRONG&gt;&lt;EM&gt;Abhi Corp MSP Total&lt;/EM&gt;&lt;/STRONG&gt;*&lt;BR /&gt;
*&lt;STRONG&gt;&lt;EM&gt;Abhi Corp Total&lt;/EM&gt;&lt;/STRONG&gt;*&lt;BR /&gt;
Aniket Corp&lt;BR /&gt;
*&lt;STRONG&gt;&lt;EM&gt;Aniket Corp Total&lt;/EM&gt;&lt;/STRONG&gt;*&lt;/P&gt;

&lt;P&gt;Also query is adding column header as 'srm'. Is it possible to have sum in same "SR Units Used" column ?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 17:58:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278351#M84021</guid>
      <dc:creator>asaste</dc:creator>
      <dc:date>2016-06-02T17:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278352#M84022</link>
      <description>&lt;P&gt;You can change the column name to be whatever you would like to be by changing the &lt;CODE&gt;as&lt;/CODE&gt; clause. Like so...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | appendpipe [|stats sum(srm_units_used) as "SR Units Used" by cust_name  ] | sort cust_name | eval cust_name=if(isnull("Ticket Id"), cust_name." Total", cust_name))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2016 21:12:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278352#M84022</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-02T21:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278353#M84023</link>
      <description>&lt;P&gt;Little variation of above to give you proper order&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=em7_srm_summary_data srm_units_used&amp;gt;0 | dedup ticket_id | sort cust_name, ticket_id | eval "Closed Date" = if (ticket_date_closed!=0, strftime(ticket_date_closed,"%m/%d/%Y"), "") | stats list("ticket_id") as "Ticket Id", list("Closed Date") as "Closed Date" ,list("srm_units_used") as "SR Units Used" by cust_name | streamstats count as serialno | appendpipe [|stats max(serialno) sum(srm_units_used) as "SR Units Used" by cust_name | eval cust_name=cust_name." Total"] | sort serialno | fields - serialno
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2016 21:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278353#M84023</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-02T21:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278354#M84024</link>
      <description>&lt;P&gt;Thanks somesoni2.&lt;BR /&gt;
I have tried your query but it is providing following order.&lt;BR /&gt;
Abhi Corp&lt;BR /&gt;
Abhi Corp MSP&lt;BR /&gt;
Aniket Corp&lt;BR /&gt;
&lt;STRONG&gt;Abhi Corp Total&lt;BR /&gt;
Abhi Corp MSP Total&lt;BR /&gt;
Aniket Corp Total&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I need following order&lt;BR /&gt;
Abhi Corp&lt;BR /&gt;
&lt;STRONG&gt;Abhi Corp Total&lt;/STRONG&gt;&lt;BR /&gt;
Abhi Corp MSP&lt;BR /&gt;
&lt;STRONG&gt;Abhi Corp MSP Total&lt;/STRONG&gt;&lt;BR /&gt;
Aniket Corp&lt;BR /&gt;
&lt;STRONG&gt;Aniket Corp Total&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Also Total it is giving as 1,2,3 instead of 35, 21, 50 as below&lt;/P&gt;

&lt;H2&gt;Customer_Name                  max(serialno)&lt;/H2&gt;

&lt;P&gt;Abhi Corp Total             1&lt;BR /&gt;
Abhi Corp MSP Total          2&lt;BR /&gt;
Aniket Corp Total               3&lt;/P&gt;

&lt;P&gt;I am currently modyfying query you have provided to get correct Sum of "SR Units Used"&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Abhi&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 05:25:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278354#M84024</guid>
      <dc:creator>asaste</dc:creator>
      <dc:date>2016-06-06T05:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to group rows together in a table and calculate the sum for each group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278355#M84025</link>
      <description>&lt;P&gt;Have you got any answer for this question? Did you get your table results in the above mentioned format?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 16:49:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-rows-together-in-a-table-and-calculate-the-sum-for/m-p/278355#M84025</guid>
      <dc:creator>harish1992</dc:creator>
      <dc:date>2017-11-15T16:49:02Z</dc:date>
    </item>
  </channel>
</rss>

