<?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: Sum categories from a main search. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689285#M234904</link>
    <description>&lt;P&gt;You can use eventstats as &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/263242"&gt;@dtburrows3&lt;/a&gt; already pointed out, just keep in mind that Splunk will put those sums into every single row in your results. It's not an Excel, you&amp;nbsp; cannot merge cells here.&lt;/P&gt;</description>
    <pubDate>Sat, 01 Jun 2024 09:27:25 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2024-06-01T09:27:25Z</dc:date>
    <item>
      <title>Sum categories from a main search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689268#M234897</link>
      <description>&lt;P&gt;Hi Cummunity team,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a complex query to gather the data below, but a new request came up, it was asked to me to add in the report email subject the product category totals by Category. with the $result.&lt;FONT color="#FF0000"&gt;productcat1&lt;/FONT&gt;$ and $result.&lt;FONT color="#FF0000"&gt;productcat2&lt;/FONT&gt;$ I could apprach that,&lt;BR /&gt;but the way I'm calculating the totals I'm not getting the expected numbers, because I'm appeding the columns from a subquery and transposing the values with&amp;nbsp;&amp;nbsp;&lt;FONT color="#000080"&gt;xyseries.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;Could you please suggest how can I sum(Sales Total) by productcat1 and&amp;nbsp;productcat2 in a new field but keeping the same output as I have now?,&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.:&lt;BR /&gt;something like if&amp;nbsp;ProducCategory="productcat1"; then&amp;nbsp; productcat1=productcat1+SalesTotal, else&amp;nbsp;productcat2=productcat2+SalesTotal&amp;nbsp;``` But Print the original output ```&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider productcat1 and&amp;nbsp;productcat2 are fixed values.&amp;nbsp;&lt;/P&gt;&lt;TABLE width="571"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="46px"&gt;ENV&lt;/TD&gt;&lt;TD width="128.587px" height="46px"&gt;ProducCategory&lt;/TD&gt;&lt;TD width="111.225px" height="46px"&gt;ProductName&lt;/TD&gt;&lt;TD width="119.787px" height="46px"&gt;SalesCondition&lt;/TD&gt;&lt;TD width="49.5625px" height="46px"&gt;SalesTotal&lt;/TD&gt;&lt;TD width="100.95px" height="46px"&gt;&lt;FONT color="#FF0000"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="46px"&gt;&lt;FONT color="#FF0000"&gt;productcat2&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productR&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;9&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&lt;FONT color="#008080"&gt;152&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;160&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productj&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;8&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productc&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;33&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productcat2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productx&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;77&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productcat2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productpp&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;89&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productcat2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;productRr&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#FFCC00"&gt;11&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productRs&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;6&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productRd&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;43&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="44.6625px" height="24px"&gt;prod&lt;/TD&gt;&lt;TD width="128.587px" height="24px"&gt;&lt;FONT color="#008080"&gt;productcat1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="111.225px" height="24px"&gt;&lt;FONT color="#008080"&gt;productRq&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="119.787px" height="24px"&gt;&lt;FONT color="#008080"&gt;blabla&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="49.5625px" height="24px"&gt;&lt;FONT color="#008080"&gt;55&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="100.95px" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 20:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689268#M234897</guid>
      <dc:creator>JMPP</dc:creator>
      <dc:date>2024-05-31T20:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum categories from a main search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689271#M234899</link>
      <description>&lt;P&gt;I think using eventstats can get you the desired output you are looking for if I am interpreting your question correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | eventstats
        sum(eval(case('ProductCategory'=="productcat1", 'Sales Total'))) as productcat1,
        sum(eval(case('ProductCategory'=="productcat2", 'Sales Total'))) as productcat2
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Or for a more dynamic approach something like this may work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | eventstats
        sum("Sales Total") as overall_sales
            by ProductCategory
    | eval
        overall_sales_json=json_object("fieldname", 'ProductCategory', "value", 'overall_sales')
    | eventstats
        values(overall_sales_json) as overall_sales_json
    | foreach mode=multivalue overall_sales_json
        [
            | eval
                fieldname=spath('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', "fieldname"),
                field_value=spath('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;', "value"),
                combined_json=if(
                    isnull(combined_json),
                        json_object(fieldname, field_value),
                        json_set(combined_json, fieldname, field_value)
                    )
            ]
    | fromjson combined_json prefix=dynamic_
    | fields - combined_json, overall_sales_json, fieldname, field_value, overall_sales
    ``` Below code is if you only want the new fields on the first row ```
    | streamstats
        count as line_number
    | foreach dynamic_*
        [
            | eval
                &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(
                    'line_number'==1,
                        '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',
                        null()
                    )
            ]
    | fields - line_number
    | rename
        dynamic_* as *&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1717194835178.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/31104i7EFC967489E15F09/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1717194835178.png" alt="dtburrows3_0-1717194835178.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 22:34:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689271#M234899</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2024-05-31T22:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sum categories from a main search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689285#M234904</link>
      <description>&lt;P&gt;You can use eventstats as &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/263242"&gt;@dtburrows3&lt;/a&gt; already pointed out, just keep in mind that Splunk will put those sums into every single row in your results. It's not an Excel, you&amp;nbsp; cannot merge cells here.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jun 2024 09:27:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689285#M234904</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-06-01T09:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sum categories from a main search.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689590#M234969</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/263242"&gt;@dtburrows3&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thanks so much it helped me a lot your suggestions, for now I will go with eventstats solutions.&lt;BR /&gt;&lt;BR /&gt;For&amp;nbsp; foreach command I need to go deep on it since it is more complex.&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;I will try&amp;nbsp;&lt;SPAN&gt;xyseries, same as I did before to have the expected single values for the productcat# fields. Need to push this report to Production ASAP.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 16:43:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-categories-from-a-main-search/m-p/689590#M234969</guid>
      <dc:creator>JMPP</dc:creator>
      <dc:date>2024-06-04T16:43:33Z</dc:date>
    </item>
  </channel>
</rss>

