<?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: Calculating total in row in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479965#M192965</link>
    <description>&lt;P&gt;It is NOT MATHEMATICALLY VALID TO SUM distinct counts!!!  You need to preserve the actual values all the way through to the very end like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats values(Users) AS Users BY Label 
| eval foo="bar" 
| xyseries foo Label Users 
| eval AplusB = mvappend(A, B)
| foreach * [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvjoin('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::") ]
| untable foo Label Users
| fields - foo 
| eval AplusB = if(Label = "AplusB", Users, null()) 
| eventstats first(AplusB) AS AplusB
| foreach Users AplusB [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = mvcount(split('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::")) ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a run-anywhere example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_* 
| rename component AS Users, log_level AS Label 
| replace "INFO" WITH "A", "ERROR" WITH "B"
| stats values(Users) AS Users BY Label 
| eval foo="bar" 
| xyseries foo Label Users 
| eval AplusB = mvappend(A, B)
| foreach * [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvjoin('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::") ]
| untable foo Label Users
| fields - foo 
| eval AplusB = if(Label = "AplusB", Users, null()) 
| eventstats first(AplusB) AS AplusB
| foreach Users AplusB [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = mvcount(split('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::")) ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Mar 2020 16:16:49 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2020-03-19T16:16:49Z</dc:date>
    <item>
      <title>Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479955#M192955</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I need help adding b+ c together to get a total, I will then calculate a percentage using a/combined b+c. Is this possible?&lt;/P&gt;

&lt;P&gt;| stats dc(Users) as UsersCount by Label app&lt;BR /&gt;
| stats sum(UsersCount) by Label&lt;/P&gt;

&lt;P&gt;Label           sum(UsersCount)&lt;BR /&gt;
1   a             14&lt;BR /&gt;
2   b              2&lt;BR /&gt;
3   c             19&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 14:20:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479955#M192955</guid>
      <dc:creator>khanyag1</dc:creator>
      <dc:date>2020-02-27T14:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479956#M192956</link>
      <description>&lt;P&gt;little clumsy solution, but maybe itll work for you&lt;BR /&gt;
try it anywhere&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data="1 a 14;;;2 b 2;;;3 c 19"
| makemv delim=";;;" data
| mvexpand data
| rex field=data "(?&amp;lt;label&amp;gt;[^\s]+)\s(?&amp;lt;app&amp;gt;[^\s]+)\s(?&amp;lt;tot_users&amp;gt;[^\s]+)"
| table label app tot_users
| rename COMMENT as "above generates fake data, below is solution"
| chart max(tot_users) as total over label by app
| stats values(*) as *
| mvexpand label
| eval b_plus_c = b + c
| eval percent = round(a / b_plus_c * 100, 2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 20:32:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479956#M192956</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2020-02-27T20:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479957#M192957</link>
      <description>&lt;P&gt;Try this (assuming field Label has values "a" "b" "c". If there are different values, update the column name in the query)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;..your base earch
| chart dc(Users) as UsersCount by app Label | fields - app
| stats sum(*) as *
| eval total=b+c
| eval percentage=round*a*100/total,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Feb 2020 20:55:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479957#M192957</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-02-27T20:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479958#M192958</link>
      <description>&lt;P&gt;Thank you! I will give this a try&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 13:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479958#M192958</guid>
      <dc:creator>khanyag1</dc:creator>
      <dc:date>2020-03-11T13:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479959#M192959</link>
      <description>&lt;P&gt;Thank you! I will try this&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 13:42:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479959#M192959</guid>
      <dc:creator>khanyag1</dc:creator>
      <dc:date>2020-03-11T13:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479960#M192960</link>
      <description>&lt;P&gt;What you are doing is &lt;STRONG&gt;&lt;EM&gt;NOT MATHEMATICALLY CORRECT!!!&lt;/EM&gt;&lt;/STRONG&gt;; you cannot sum &lt;CODE&gt;distinct counts&lt;/CODE&gt;; think about it...&lt;BR /&gt;
So do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats dc(Users) AS UsersCount BY Label
| eval foo="bar"
| xyseries foo Label UsersCount
| eval AplusB = A + B
| untable foo Label UsersCount
| fields - foo
| eval AplusB = if(Label = "AplusB", UsersCount, null())
| eventstats first(AplusB) AS AplusB
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2020 14:43:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479960#M192960</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-11T14:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479961#M192961</link>
      <description>&lt;P&gt;If my Label displays three labels, how do I extract the labels so that I can add them? Thanks for your response!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 13:12:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479961#M192961</guid>
      <dc:creator>khanyag1</dc:creator>
      <dc:date>2020-03-12T13:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479962#M192962</link>
      <description>&lt;P&gt;NO, NO, NO!!!  It is NOT MATHEMATICALLY VALID TO SUM &lt;CODE&gt;distinct counts&lt;/CODE&gt;!!!  DO NOT DEPLOY THIS.  Although this answer does what you asked, you should not be asking this.  It is as wrong as can possibly be.  This is bad math, and will lead to WRONG DECISIONS!!!!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 15:51:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479962#M192962</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-19T15:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479963#M192963</link>
      <description>&lt;P&gt;NO, NO, NO!!! It is NOT MATHEMATICALLY VALID TO SUM distinct counts!!! DO NOT DEPLOY THIS. Although this answer does what you asked, you should not be asking this. It is as wrong as can possibly be. This is bad math, and will lead to WRONG DECISIONS!!!!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 15:52:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479963#M192963</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-19T15:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479964#M192964</link>
      <description>&lt;P&gt;Keep in mind that this answer was for EDUCATIONAL PURPOSES ONLY.  It is NOT MATHEMATICALLY VALID TO SUM distinct counts!!! DO NOT DEPLOY THIS. Although this answer does what you asked, you should not be asking this. It is as wrong as can possibly be. This is bad math, and will lead to WRONG DECISIONS!!!!  I am working on a solution that will work.  Stand by.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 15:53:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479964#M192964</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-19T15:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479965#M192965</link>
      <description>&lt;P&gt;It is NOT MATHEMATICALLY VALID TO SUM distinct counts!!!  You need to preserve the actual values all the way through to the very end like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats values(Users) AS Users BY Label 
| eval foo="bar" 
| xyseries foo Label Users 
| eval AplusB = mvappend(A, B)
| foreach * [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvjoin('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::") ]
| untable foo Label Users
| fields - foo 
| eval AplusB = if(Label = "AplusB", Users, null()) 
| eventstats first(AplusB) AS AplusB
| foreach Users AplusB [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = mvcount(split('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::")) ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a run-anywhere example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_* 
| rename component AS Users, log_level AS Label 
| replace "INFO" WITH "A", "ERROR" WITH "B"
| stats values(Users) AS Users BY Label 
| eval foo="bar" 
| xyseries foo Label Users 
| eval AplusB = mvappend(A, B)
| foreach * [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=mvjoin('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::") ]
| untable foo Label Users
| fields - foo 
| eval AplusB = if(Label = "AplusB", Users, null()) 
| eventstats first(AplusB) AS AplusB
| foreach Users AplusB [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = mvcount(split('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ":::")) ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 16:16:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479965#M192965</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-19T16:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating total in row</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479966#M192966</link>
      <description>&lt;P&gt;See my other answer.  It does it the right way keeping the values, not the counts.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 16:31:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-total-in-row/m-p/479966#M192966</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-19T16:31:06Z</dc:date>
    </item>
  </channel>
</rss>

