<?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 sum all values for fields that contain a specific string? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278159#M83970</link>
    <description>&lt;P&gt;Hi, even with dots it still seems to be working fine for me. The dots are renamed to _ automatically but that's all.&lt;BR /&gt;
Maybe you have to fillnull those empty values you might find so that the subtotal works.&lt;/P&gt;

&lt;P&gt;See if the following helps:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval subtotal = 0
| fillnull value=0
| foreach Product* [ eval subtotal = subtotal + '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| eventstats sum(subtotal) as TOTAL, sum(Product*) as Product*_subtotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is what I get in my lab (see attached picture):&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/btUDzLJ.png" alt="alt text" /&gt;&lt;BR /&gt;
&lt;A href="http://i.imgur.com/btUDzLJ.png"&gt;http://i.imgur.com/btUDzLJ.png&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If that doesn't work I would suggest for you to raise a new question and provide as much info as you can (log samples, queries you are running, etc).&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jan 2017 14:11:45 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2017-01-26T14:11:45Z</dc:date>
    <item>
      <title>How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278153#M83964</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;In the events, I have different fields for the products. How can I easily sum all values for these fields when I don't know all exact names?&lt;/P&gt;

&lt;P&gt;productA=&lt;BR /&gt;
productB=&lt;BR /&gt;
productC=&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;These examples are not working, but I hope it explains my need:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(product*) AS total_products
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or to sum up all values per product&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(product*) AS sum BY product*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance&lt;BR /&gt;
Heinz&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 10:49:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278153#M83964</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-12-13T10:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278154#M83965</link>
      <description>&lt;P&gt;Hi HeinzWaescher&lt;BR /&gt;
try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(product*) AS total_products
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 11:18:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278154#M83965</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2016-12-13T11:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278155#M83966</link>
      <description>&lt;P&gt;If I understand correctly you have several products per event and you don't know the names beforehand right?&lt;/P&gt;

&lt;P&gt;Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1: Time=123 ProductA=1 ProductB=10 ProductC=100
Event2: Time=456 ProductA=2 ProductH=20 ProductC=200
Event3: Time=789 ProductD=3 ProductB=30 ProductC=300
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And you would like to display:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1: Subtotal=111
Event2: Subtotal=222
Event3: Subtotal=333
TOTAL=666
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But also:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ProductA_subtotal=3
ProductB_subtotal=40
ProductC_subtotal=600
etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If that's the case then try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here
| eval subtotal = 0
| foreach product* [ eval subtotal = subtotal + '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| stats sum(subtotal) as TOTAL, sum(product*) as product*_subtotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps. If not please give us more information (sample data, or something like that).&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 11:44:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278155#M83966</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-12-13T11:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278156#M83967</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;last month I thought that this approach works. I have a new usecase and I'm facing the problem, that it is working with one single event. But for a search returning more than 1 events it does not work. The subtotal is always 0 after the foreach command. Any ideas why this happens?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 13:20:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278156#M83967</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-01-26T13:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278157#M83968</link>
      <description>&lt;P&gt;Hi, can't really comment without seeing exactly what your data looks like as I'm not quite sure what you mean.&lt;/P&gt;

&lt;P&gt;Would you mind raising a new question so that we can look at the new use case separately rather than working on an already-closed one?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 13:23:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278157#M83968</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2017-01-26T13:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278158#M83969</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I just found out that the problem seems to be that my  fieldnames contain dots:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Event1: Time=123 Product.A=1 Product.B=10 Product.C=100
 Event2: Time=456 Product.A=2 Product.H=20 Product.C=200
 Event3: Time=789 Product.D=3 Product.B=30 Product.C=300
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But of course I can create a new question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 13:34:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278158#M83969</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-01-26T13:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278159#M83970</link>
      <description>&lt;P&gt;Hi, even with dots it still seems to be working fine for me. The dots are renamed to _ automatically but that's all.&lt;BR /&gt;
Maybe you have to fillnull those empty values you might find so that the subtotal works.&lt;/P&gt;

&lt;P&gt;See if the following helps:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval subtotal = 0
| fillnull value=0
| foreach Product* [ eval subtotal = subtotal + '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| eventstats sum(subtotal) as TOTAL, sum(Product*) as Product*_subtotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is what I get in my lab (see attached picture):&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/btUDzLJ.png" alt="alt text" /&gt;&lt;BR /&gt;
&lt;A href="http://i.imgur.com/btUDzLJ.png"&gt;http://i.imgur.com/btUDzLJ.png&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If that doesn't work I would suggest for you to raise a new question and provide as much info as you can (log samples, queries you are running, etc).&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 14:11:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278159#M83970</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2017-01-26T14:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum all values for fields that contain a specific string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278160#M83971</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I created a standard example as well, which works fine:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | head 10

| eval product.A=1
| eval product.B=2
| eval product.C=3

| eval subtotal = 0
| foreach product* [ eval subtotal = subtotal + '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']

| table subtotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But you are right, in my real usecase not every event includes every product.x. Fillnull fixes this problem and foreach is working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 14:22:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-all-values-for-fields-that-contain-a-specific-string/m-p/278160#M83971</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-01-26T14:22:06Z</dc:date>
    </item>
  </channel>
</rss>

