<?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: Combine the Sum of Two Fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497879#M138713</link>
    <description>&lt;P&gt;Combine 4 and 5 before calling &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex "Search Term" NOT field=value source="mylog.log" 
| eval totalx=aCount+bCount, y=case(y=4 OR y=5, 45, 1==1, y) 
| stats sum(totalx) by y | sort -sum(totalx)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Mar 2020 17:28:22 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-03-19T17:28:22Z</dc:date>
    <item>
      <title>Combine the Sum of Two Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497878#M138712</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;For a search similar to the following:&lt;BR /&gt;
index=myindex "Search Term" NOT field=value source="mylog.log" | eval totalx=aCount+bCount | stats sum(totalx) by y | sort -sum(totalx)&lt;/P&gt;

&lt;P&gt;Splunk returns exactly the data I am looking for.  A table of sum(totalx) by y (of which there are around 5 different values of y).  I have a request to combine the sum(totalx) values for 2 of the 5 values and treat them as one value but leave the rest unchanged.  What would be the best way to accomplish this?&lt;/P&gt;

&lt;P&gt;For instance, right now my search returns a table similar to this:&lt;BR /&gt;
y           sum(totalx)&lt;BR /&gt;
1          10&lt;BR /&gt;
2          20&lt;BR /&gt;
3          30&lt;BR /&gt;
4          40&lt;BR /&gt;
5          50&lt;/P&gt;

&lt;P&gt;I am essentially trying to create an additional field, let's call it 45, which represents the sum of 4 and 5 at all times.  So instead, the data being visualized is:&lt;BR /&gt;
y           sum(totalx)&lt;BR /&gt;
1          10&lt;BR /&gt;
2          20&lt;BR /&gt;
3          30&lt;BR /&gt;
45        90&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 17:21:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497878#M138712</guid>
      <dc:creator>bcarr12</dc:creator>
      <dc:date>2020-03-19T17:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Combine the Sum of Two Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497879#M138713</link>
      <description>&lt;P&gt;Combine 4 and 5 before calling &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex "Search Term" NOT field=value source="mylog.log" 
| eval totalx=aCount+bCount, y=case(y=4 OR y=5, 45, 1==1, y) 
| stats sum(totalx) by y | sort -sum(totalx)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 17:28:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497879#M138713</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-03-19T17:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combine the Sum of Two Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497880#M138714</link>
      <description>&lt;P&gt;Hmm, this doesn't seem to do anything.  Although I think it doesn't work because if I don't do stats I don't get the numerical values to combine.  Stats is what causes the totalx by y to become available.  Before I run stats y is just a text field=value pair that is non numerical if that makes sense?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 17:40:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497880#M138714</guid>
      <dc:creator>bcarr12</dc:creator>
      <dc:date>2020-03-19T17:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Combine the Sum of Two Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497881#M138715</link>
      <description>&lt;P&gt;Field y must exist before &lt;CODE&gt;stats&lt;/CODE&gt; or you'll get no results.&lt;BR /&gt;
The &lt;CODE&gt;case&lt;/CODE&gt; function in my answer is doing the combining.  It doesn't need numeric values (if you have nonnumeric values, use quotation marks &lt;CODE&gt;(y="d" OR y="e", "de")&lt;/CODE&gt;).  It produces data like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1 10
2 20
3 30
45 40
45 50
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then &lt;CODE&gt;stats&lt;/CODE&gt; can do the sums to produce&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1 10
2 20
3 30
45 90
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 22:08:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-the-Sum-of-Two-Fields/m-p/497881#M138715</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-03-19T22:08:02Z</dc:date>
    </item>
  </channel>
</rss>

