<?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 add two fields together based on a condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287928#M87150</link>
    <description>&lt;P&gt;You can use the &lt;CODE&gt;if&lt;/CODE&gt; statement.. like this &lt;CODE&gt;.. | eval score=if(user&amp;gt;0, user+scrore, score)&lt;/CODE&gt; OR &lt;/P&gt;

&lt;P&gt;what if you always add the two fields &lt;CODE&gt;.. | eval score=score+user&lt;/CODE&gt;, if the &lt;CODE&gt;user&lt;/CODE&gt; field is null, &lt;CODE&gt;score&lt;/CODE&gt; will be just &lt;CODE&gt;score&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The 3rd option, not sure this is right for your situation &lt;CODE&gt;.. | eval score=coalesce(score, user)&lt;/CODE&gt;. this will work ONLY if only one or the other has a value. if both have values, this will not add.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2016 17:24:38 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-04-12T17:24:38Z</dc:date>
    <item>
      <title>How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287927#M87149</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Background Information:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I have an index from a tool that is being fed into Splunk. The tool has a &lt;STRONG&gt;score&lt;/STRONG&gt; field and a &lt;STRONG&gt;user&lt;/STRONG&gt; field.  However, the tool sometimes gives two separate scores for the same user (because of a session issue).  I'm trying to create a panel in Splunk that shows the score for each user.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Is there some type of sum or eval statement I can use to add scores together if a particular user has two separate scores?&lt;/P&gt;

&lt;P&gt;This is my search so far...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype=test2 | WHERE score&amp;gt;=100 | eval Date=strftime(_time, " %d %b %Y %H:%I:%S") | table Date, user, score
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 16:57:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287927#M87149</guid>
      <dc:creator>SplvnkGirl</dc:creator>
      <dc:date>2016-04-12T16:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287928#M87150</link>
      <description>&lt;P&gt;You can use the &lt;CODE&gt;if&lt;/CODE&gt; statement.. like this &lt;CODE&gt;.. | eval score=if(user&amp;gt;0, user+scrore, score)&lt;/CODE&gt; OR &lt;/P&gt;

&lt;P&gt;what if you always add the two fields &lt;CODE&gt;.. | eval score=score+user&lt;/CODE&gt;, if the &lt;CODE&gt;user&lt;/CODE&gt; field is null, &lt;CODE&gt;score&lt;/CODE&gt; will be just &lt;CODE&gt;score&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The 3rd option, not sure this is right for your situation &lt;CODE&gt;.. | eval score=coalesce(score, user)&lt;/CODE&gt;. this will work ONLY if only one or the other has a value. if both have values, this will not add.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287928#M87150</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-12T17:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287929#M87151</link>
      <description>&lt;P&gt;the thing is user is not an integer...can this be achieved via Distinct Count somehow?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287929#M87151</guid>
      <dc:creator>SplvnkGirl</dc:creator>
      <dc:date>2016-04-12T18:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287930#M87152</link>
      <description>&lt;P&gt;I'm not sure I entirely follow the requirements. Some notes:&lt;/P&gt;

&lt;P&gt;Move the &lt;CODE&gt;score&amp;gt;=100&lt;/CODE&gt; qualifier into the main search.&lt;/P&gt;

&lt;P&gt;Use &lt;CODE&gt;stats&lt;/CODE&gt; maybe to aggregate the data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype=test2 score&amp;gt;=100 | 
stats sum(score) as Score latest(_time) as _time by user | 
fields _time, user, Score
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:49:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287930#M87152</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2016-04-12T18:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287931#M87153</link>
      <description>&lt;P&gt;I misunderstood. Which field has the second score? Are both scores on the same event? or are they separate events? If they are different events, you can summaries like this&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;.... | stats sum(score) as score sum(second_score) as second_score by user | addtotals&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;This will add a total column with the sum of score and second_score.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:06:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287931#M87153</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-12T19:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287932#M87154</link>
      <description>&lt;P&gt;So I have a tool that gives user's scores.  I have logs coming into Splunk for this tool.  For some reason the logs in splunk shows one user with two separate scores when I use this search:&lt;/P&gt;

&lt;P&gt;index=test sourcetype=test2 | WHERE score&amp;gt;=100 | eval Date=strftime(_time, " %d %b %Y %H:%I:%S") | table Date, user, score&lt;/P&gt;

&lt;P&gt;I'm only concerned about users who have a score if 100 or above.  The user who shows up twice in Splunk has a score above 100 in my tool but on the logs in Splunk the user is shown twice with two different scores (that add up to over 100).  Basically the user shows up in the table twice. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;example&lt;/STRONG&gt;&lt;/P&gt;

&lt;H2&gt;user   |   score&lt;/H2&gt;

&lt;P&gt;bmith |  56&lt;BR /&gt;
rscott | 26&lt;BR /&gt;
jdoe | 78&lt;BR /&gt;
kwarren | 112&lt;BR /&gt;
bsmith | 48&lt;/P&gt;

&lt;P&gt;I'm trying to achieve this:&lt;/P&gt;

&lt;H2&gt;user   |   score&lt;/H2&gt;

&lt;P&gt;bsmith | 104&lt;BR /&gt;
kwarren | 112&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 20:17:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287932#M87154</guid>
      <dc:creator>SplvnkGirl</dc:creator>
      <dc:date>2016-04-12T20:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287933#M87155</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype=test2  | eval Date=strftime(_time, " %d %b %Y %H:%I:%S") | stats sum(score) as score by Date user | where score&amp;gt;=100  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 21:39:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287933#M87155</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-12T21:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287934#M87156</link>
      <description>&lt;P&gt;Hi,  &lt;/P&gt;

&lt;P&gt;This returns 0 results.  It's most likely because I don't currently have a user who has a score over 100. I need the search to add the scores or combine the rows of users who show up more than once in the logs. I removed the table and clicked the "user" interesting fields to show that there are two users who have a count of 2.  That makes them show up twice in the logs with two separate scores.  I need a way to combine any user that has a count of more than 1 to show their total score.  Thanks for your continued help!&lt;/P&gt;

&lt;P&gt;Screenshot&lt;BR /&gt;
&lt;A href="http://pasteboard.co/9MCXOBt.png"&gt;http://pasteboard.co/9MCXOBt.png&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 14:03:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287934#M87156</guid>
      <dc:creator>SplvnkGirl</dc:creator>
      <dc:date>2016-04-13T14:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two fields together based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287935#M87157</link>
      <description>&lt;P&gt;Should there have been users with score greater than 100?&lt;/P&gt;

&lt;P&gt;That &lt;CODE&gt;| stats sum(score) by date user&lt;/CODE&gt; command will add all the score for the same user. So, in your example if there are two events for a user, the stats command will add the score from both events. You could test by removing the &lt;CODE&gt;| where score&amp;gt;=100&lt;/CODE&gt; to see if there are duplicate users and if there are any users with score greater than 100&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 15:54:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-two-fields-together-based-on-a-condition/m-p/287935#M87157</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-14T15:54:34Z</dc:date>
    </item>
  </channel>
</rss>

