<?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 get the sum according to field values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294288#M88859</link>
    <description>&lt;P&gt;Hi @ micahkemp, thanks for your reply! It worked! I am just having problems with my % calculation.&lt;BR /&gt;
I think I didn't make it clear enough. Sorry for that.&lt;BR /&gt;
%A = (Position1/(Position1 + Position2) * 100&lt;BR /&gt;
%B = (Position2/(Position1 + Position2) * 100&lt;BR /&gt;
and the number format should be in %&lt;BR /&gt;
I can only use the division function but I can't combine it with the sum.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2018 02:48:00 GMT</pubDate>
    <dc:creator>auaave</dc:creator>
    <dc:date>2018-01-11T02:48:00Z</dc:date>
    <item>
      <title>How to get the sum according to field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294286#M88857</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;

&lt;P&gt;I am counting the number of events from field name "LOCATION".This Field have 4 locations, Location A,B,C and D.&lt;BR /&gt;
I need to get the count of events from Location A B and C and name it as Position 1 Events then events from Location D as Position 2.&lt;BR /&gt;
Then after that, I need to get the percentage of events from Position 1 (ABC) and Position 2 (D).&lt;/P&gt;

&lt;P&gt;How can I do that?&lt;/P&gt;

&lt;P&gt;Thank you! &lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 02:08:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294286#M88857</guid>
      <dc:creator>auaave</dc:creator>
      <dc:date>2018-01-11T02:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum according to field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294287#M88858</link>
      <description>&lt;P&gt;One option is to use &lt;CODE&gt;stats&lt;/CODE&gt; with &lt;CODE&gt;count(eval())&lt;/CODE&gt; to get counts of each location, then determine the percent at the end (I'm not sure which direction you want the percent, so you may need to flip that portion:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | makeresults
    | append [| makeresults | eval LOCATION="A"]
    | append [| makeresults | eval LOCATION="B"]
    | append [| makeresults | eval LOCATION="C"]
    | append [| makeresults | eval LOCATION="D"]
    | stats count(eval(LOCATION="A" OR LOCATION="B" OR LOCATION="C")) AS "Position 1 Events", count(eval(LOCATION="D")) AS "Position 2 Events"
    | eval Position1Pct='Position 1 Events'/('Position 1 Events'+'Position 2 Events')*100, Position2Pct='Position 2 Events'/('Position 1 Events'+'Position 2 Events')*100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another option is to use something closer to a lookup (faked with a &lt;CODE&gt;case&lt;/CODE&gt; statement here) to translate LOCATION to position, then perform the same count/eval method:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | makeresults
    | append [| makeresults | eval LOCATION="A"]
    | append [| makeresults | eval LOCATION="B"]
    | append [| makeresults | eval LOCATION="C"]
    | append [| makeresults | eval LOCATION="D"]
    | eval position=case(LOCATION="A" OR LOCATION="B" OR LOCATION="C", 1, LOCATION="D", 2)
    | stats count(eval(position=1)) AS "Position 1 Events", count(eval(position=2)) AS "Position 2 Events"
    | eval Position1Pct='Position 1 Events'/('Position 1 Events'+'Position 2 Events')*100, Position2Pct='Position 2 Events'/('Position 1 Events'+'Position 2 Events')*100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 02:25:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294287#M88858</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-11T02:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum according to field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294288#M88859</link>
      <description>&lt;P&gt;Hi @ micahkemp, thanks for your reply! It worked! I am just having problems with my % calculation.&lt;BR /&gt;
I think I didn't make it clear enough. Sorry for that.&lt;BR /&gt;
%A = (Position1/(Position1 + Position2) * 100&lt;BR /&gt;
%B = (Position2/(Position1 + Position2) * 100&lt;BR /&gt;
and the number format should be in %&lt;BR /&gt;
I can only use the division function but I can't combine it with the sum.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 02:48:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294288#M88859</guid>
      <dc:creator>auaave</dc:creator>
      <dc:date>2018-01-11T02:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum according to field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294289#M88860</link>
      <description>&lt;P&gt;Updated answer to reflect the percentage.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 02:53:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294289#M88860</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-11T02:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum according to field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294290#M88861</link>
      <description>&lt;P&gt;@micahkemp, thanks a lot! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 03:01:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-according-to-field-values/m-p/294290#M88861</guid>
      <dc:creator>auaave</dc:creator>
      <dc:date>2018-01-11T03:01:34Z</dc:date>
    </item>
  </channel>
</rss>

