<?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: Arithmatic operations based on selected rows in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300180#M164980</link>
    <description>&lt;P&gt;Hi cmerriman,&lt;/P&gt;

&lt;P&gt;Thanks for the input, based on that i updated my condition and tried, however in total sum i am not getting expected output. ie.,i want to sum category group A, B and C but not D. but my total sum includes D as well ie., A+B+C+D as E and F as E-D which is not correct, please advice.&lt;/P&gt;

&lt;P&gt;i simplified my search by considering only category group as category may have more/less items depends on the condition.&lt;/P&gt;

&lt;P&gt;my search&lt;BR /&gt;
|eval group1= if(("Category Group"="A") OR ("Category Group"="B") OR ("Category Group"="C") &lt;BR /&gt;
 AND("Category Group"!= "D"),0,Price)&lt;BR /&gt;
|appendpipe [stats sum(group1) as Price|fillnull Category value=E1 |fillnull "Category Group" value=E]&lt;BR /&gt;
 |autoregress Price|appendpipe [eval Price=if(Category="E1",Price-Price_p1,null())&lt;BR /&gt;
|replace E* with F* in Category, "Category Group" |where isnotnull(Price)]&lt;BR /&gt;
|fields - group1 Price_p1&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:56:16 GMT</pubDate>
    <dc:creator>deepa_purushoth</dc:creator>
    <dc:date>2020-09-29T16:56:16Z</dc:date>
    <item>
      <title>Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300172#M164972</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I am a beginer&lt;BR /&gt;
My data something like this&lt;BR /&gt;
CategoryGroup | Category |Price&lt;BR /&gt;
A|A1|1&lt;BR /&gt;
B|B1|2&lt;BR /&gt;
B|B2|3&lt;BR /&gt;
C|C1|1&lt;BR /&gt;
C|C2|2&lt;BR /&gt;
C|C3|4&lt;BR /&gt;
D|D1|3&lt;BR /&gt;
D|D2|2&lt;/P&gt;

&lt;P&gt;I want to add selective rows based on price and display it as new row, further i want to find difference/avg/% and to be displayed each as new rows (col is also ok)&lt;BR /&gt;
for example&lt;BR /&gt;
A|A1|1&lt;BR /&gt;
B|B1|2&lt;BR /&gt;
B|B2|3&lt;BR /&gt;
C|C1|1&lt;BR /&gt;
C|C2|2&lt;BR /&gt;
C|C3|4&lt;BR /&gt;
D|D1|3&lt;BR /&gt;
D|D2|2&lt;BR /&gt;
E|E1|9 (ie., sum of A,B and C based on selected CategoryGroup&lt;BR /&gt;
F|f1|7 (ie., difference of E and D , base don selected category group.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 17:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300172#M164972</guid>
      <dc:creator>deepa_purushoth</dc:creator>
      <dc:date>2017-11-21T17:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300173#M164973</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;&lt;BR /&gt;
Can you please try this search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH
| table CategoryGroup, Category,Price
| eval Price1=if(CategoryGroup="D",0,Price) | addcoltotals |fillnull value="E" CategoryGroup |fillnull value="E1" Category | eval Price3=case(CategoryGroup="D",Price * (-1),CategoryGroup="E",Price)  | addcoltotals |fillnull value="F" CategoryGroup |fillnull value="F1" Category | eval Price=case(CategoryGroup="D",Price,CategoryGroup="E" OR CategoryGroup="F",Price3,1=1,Price) | table CategoryGroup Category Price
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 17:58:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300173#M164973</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-21T17:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300174#M164974</link>
      <description>&lt;P&gt;do you mean based on selected Category &lt;STRONG&gt;and&lt;/STRONG&gt; CategoryGroup?&lt;/P&gt;

&lt;P&gt;It looks like, in your example, that E|E1|9 would be the sum of A1, B1, B2, C1, C2, but not C3. and f1 would be the difference of E1 and D2.  &lt;/P&gt;

&lt;P&gt;you could do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults |eval data="CategoryGroup=A,Category=A1,Price=1 CategoryGroup=B,Category=B1,Price=2 CategoryGroup=B,Category=B2,Price=3 CategoryGroup=C,Category=C1,Price=1 CategoryGroup=C,Category=C2,Price=2 CategoryGroup=C,Category=C3,Price=4 CategoryGroup=D,Category=D1,Price=3 CategoryGroup=D,Category=D2,Price=2"|makemv data|mvexpand data|rename data as _raw|kv|table CategoryGroup Category Price|eval group1=if((like(Category,"%1") OR like(Category,"%2")) AND in(CategoryGroup,"A","B","C"),Price,0)|appendpipe [stats sum(group1) as Price|fillnull Category value=E1 |fillnull CategoryGroup value=E]|autoregress Price|appendpipe [eval Price=if(Category="E1",Price-Price_p1,null())|replace E* with F* in Category, CategoryGroup |where isnotnull(Price)] |fields - group1 Price_p1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Nov 2017 19:06:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300174#M164974</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-11-21T19:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300175#M164975</link>
      <description>&lt;P&gt;Hi cmerriman,&lt;BR /&gt;
Thanks, i tried running this query but am getting error ": This command must be the first command of a search" and also i would like to add the price column is not indexed field it is derived field so i excluded that field while running. Further I restricted my search only to field "Category group" as the Category and Price field value is not static.&lt;BR /&gt;
Can you please help me here? Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 09:24:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300175#M164975</guid>
      <dc:creator>deepa_purushoth</dc:creator>
      <dc:date>2017-11-22T09:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300176#M164976</link>
      <description>&lt;P&gt;and also Error in 'eval' command: The 'in' function is unsupported or undefined. &lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 09:50:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300176#M164976</guid>
      <dc:creator>deepa_purushoth</dc:creator>
      <dc:date>2017-11-22T09:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300177#M164977</link>
      <description>&lt;P&gt;Hi  kamlesh_vaghela.&lt;/P&gt;

&lt;P&gt;Thanks, however can you please explain me the query flow, because the total adds up is not correct, it is fetching first and the last row. &lt;BR /&gt;
I treid adding more than one condition using OR in line 3, but it didnt work...⚠  Error in 'eval' command: The expression is malformed. Expected ). &lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 12:07:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300177#M164977</guid>
      <dc:creator>deepa_purushoth</dc:creator>
      <dc:date>2017-11-22T12:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300178#M164978</link>
      <description>&lt;P&gt;Sorry, what I sent was just as an example, a run anywhere set. &lt;BR /&gt;
Try to use the query from &lt;CODE&gt;eval group1&lt;/CODE&gt; and down. &lt;/P&gt;

&lt;P&gt;The in function is also only available after v6.6. &lt;BR /&gt;
It can be replaced with &lt;CODE&gt;(CategoryGroup="A" OR CategoryGroup="B" OR CategoryGroup="C")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 12:50:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300178#M164978</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-11-22T12:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300179#M164979</link>
      <description>&lt;P&gt;Hi@deepa_purushothaman,&lt;/P&gt;

&lt;P&gt;I'm using this search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval CategoryGroup="A", Category="A1",Price="1" 
| append 
    [| makeresults 
    | eval CategoryGroup="B", Category="B1",Price="2" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="B", Category="B2",Price="3" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="C", Category="C1",Price="1" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="C", Category="C2",Price="2" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="C", Category="C3",Price="3" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="D", Category="D1",Price="3" ] 
| append 
    [| makeresults 
    | eval CategoryGroup="D", Category="D2",Price="2" ] 
| table CategoryGroup, Category,Price 
| eval Price1=if(CategoryGroup="D",0,Price) 
| addcoltotals 
| fillnull value="E" CategoryGroup 
| fillnull value="E1" Category 
| eval Price3=case(CategoryGroup="D",Price * (-1),CategoryGroup="E",Price) 
| addcoltotals 
| fillnull value="F" CategoryGroup 
| fillnull value="F1" Category 
| eval Price=case(CategoryGroup="D",Price,CategoryGroup="E" OR CategoryGroup="F",Price3,1=1,Price) 
| table CategoryGroup Category Price
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this search, with category A, B, C &amp;amp; D, &lt;BR /&gt;
create a new category "E" which has total value of A + B + C. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Price1=if(CategoryGroup="D",0,Price) 
| addcoltotals 
| fillnull value="E" CategoryGroup 
| fillnull value="E1" Category 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then creating "F" category which has E - D values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Price3=case(CategoryGroup="D",Price * (-1),CategoryGroup="E",Price) 
| addcoltotals 
| fillnull value="F" CategoryGroup 
| fillnull value="F1" Category 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then again assigning Price fields to a particular category.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Price=case(CategoryGroup="D",Price,CategoryGroup="E" OR CategoryGroup="F",Price3,1=1,Price) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;can you please share your sample search in which you get the error?&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 17:22:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300179#M164979</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-22T17:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300180#M164980</link>
      <description>&lt;P&gt;Hi cmerriman,&lt;/P&gt;

&lt;P&gt;Thanks for the input, based on that i updated my condition and tried, however in total sum i am not getting expected output. ie.,i want to sum category group A, B and C but not D. but my total sum includes D as well ie., A+B+C+D as E and F as E-D which is not correct, please advice.&lt;/P&gt;

&lt;P&gt;i simplified my search by considering only category group as category may have more/less items depends on the condition.&lt;/P&gt;

&lt;P&gt;my search&lt;BR /&gt;
|eval group1= if(("Category Group"="A") OR ("Category Group"="B") OR ("Category Group"="C") &lt;BR /&gt;
 AND("Category Group"!= "D"),0,Price)&lt;BR /&gt;
|appendpipe [stats sum(group1) as Price|fillnull Category value=E1 |fillnull "Category Group" value=E]&lt;BR /&gt;
 |autoregress Price|appendpipe [eval Price=if(Category="E1",Price-Price_p1,null())&lt;BR /&gt;
|replace E* with F* in Category, "Category Group" |where isnotnull(Price)]&lt;BR /&gt;
|fields - group1 Price_p1&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:56:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300180#M164980</guid>
      <dc:creator>deepa_purushoth</dc:creator>
      <dc:date>2020-09-29T16:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmatic operations based on selected rows</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300181#M164981</link>
      <description>&lt;P&gt;it looks like your search is actually ONLY summing &lt;CODE&gt;D&lt;/CODE&gt; as &lt;CODE&gt;E&lt;/CODE&gt; and then subtracting the last value of &lt;CODE&gt;D&lt;/CODE&gt; (in your original example, it would be a 2), from &lt;CODE&gt;E&lt;/CODE&gt; as &lt;CODE&gt;F&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval group1= if(('Category Group'="A") OR ('Category Group'="B") OR ('Category Group'="C") AND ('Category Group'!= "D"),Price,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2017 12:52:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Arithmatic-operations-based-on-selected-rows/m-p/300181#M164981</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-11-27T12:52:29Z</dc:date>
    </item>
  </channel>
</rss>

