<?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 generate a search to calculate new column value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291584#M88068</link>
    <description>&lt;P&gt;niketnilay - This works fine for 6.5.x but I m running on 6.3.3&lt;BR /&gt;
Any alternate solution for it.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 20:12:27 GMT</pubDate>
    <dc:creator>praveerg</dc:creator>
    <dc:date>2017-03-22T20:12:27Z</dc:date>
    <item>
      <title>How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291582#M88066</link>
      <description>&lt;P&gt;Sample data below.&lt;BR /&gt;
I need to compute the col_3  based on col_1. It should give me the running sum of col_2 but should reset to 0 if col_2 is zero for a given col_1 value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;col_1   col_2   col_3
A       1       1
A       0       0
A       2       2
A       3       5
A       0       0
B       2       2
B       0       0
B       0       0
B       1       1
B       1       2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:22:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291582#M88066</guid>
      <dc:creator>praveerg</dc:creator>
      <dc:date>2020-09-29T13:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291583#M88067</link>
      <description>&lt;P&gt;Try the following &lt;STRONG&gt;streamstats&lt;/STRONG&gt; command with your base search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;YourBaseSearch&amp;gt;
| streamstats sum(col_2) as col_3 by col_1 reset_before="("match(col_2,\"0\")")" reset_on_change=true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to Splunk documentation for &lt;STRONG&gt;reset_before&lt;/STRONG&gt; and &lt;STRONG&gt;reset_on_change&lt;/STRONG&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:22:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291583#M88067</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T13:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291584#M88068</link>
      <description>&lt;P&gt;niketnilay - This works fine for 6.5.x but I m running on 6.3.3&lt;BR /&gt;
Any alternate solution for it.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 20:12:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291584#M88068</guid>
      <dc:creator>praveerg</dc:creator>
      <dc:date>2017-03-22T20:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291585#M88069</link>
      <description>&lt;P&gt;I'm on 6.4, so this is not a solution for you.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Note, the &lt;CODE&gt;reset_before&lt;/CODE&gt; command needs to use a numeric compare, or it will match &lt;CODE&gt;10&lt;/CODE&gt; as well as &lt;CODE&gt;0&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval mydata="A,1 A,0 A,2 A,3 A,0 A,1 B,2 B,10 B,0 B,1 B,1" | makemv mydata| mvexpand mydata
| rex field=mydata "(?&amp;lt;col_1&amp;gt;[^,]*),(?&amp;lt;col_2&amp;gt;.*)" | table col_1 col_2
| streamstats sum(col_2) as col_3 by col_1 reset_before="col_2==0"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I added one final &lt;CODE&gt;A,1&lt;/CODE&gt; record to prove that the first &lt;CODE&gt;B&lt;/CODE&gt; would reset to &lt;CODE&gt;0&lt;/CODE&gt; before adding its value, receiving the following output...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; col_1    col_2    col_3
   A        1        1
   A        0        0
   A        2        2
   A        3        5
   A        0        0
   A        1        1
   B        2        2
   B       10       12
   B        0        0
   B        1        1
   B        1        2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 14:44:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291585#M88069</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-23T14:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291586#M88070</link>
      <description>&lt;P&gt;Another alternative (works on 6.2.12 so should work on 6.3.3&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval mydata="A,1 A,0 A,2 A,3 A,0 A,1 B,2 B,10 B,0 B,1 B,1" | makemv mydata| mvexpand mydata
| rex field=mydata "(?&amp;lt;col_1&amp;gt;[^,]*),(?&amp;lt;col_2&amp;gt;.*)" | table col_1 col_2 
| eval temp=if(col_2=0,1,0) | accum temp | streamstats sum(col_2) as col_3 by temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:01:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291586#M88070</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-23T15:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291587#M88071</link>
      <description>&lt;P&gt;I don't see the option reset_before option in the streamstats document for 6.3.3. May be it's available but un-documented.&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.3.3/SearchReference/Streamstats"&gt;https://docs.splunk.com/Documentation/Splunk/6.3.3/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:02:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291587#M88071</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-23T15:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291588#M88072</link>
      <description>&lt;P&gt;crud.  They've finished the upgrades to my boxes to 6.4 ... updating answer...&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:44:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291588#M88072</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-23T15:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a search to calculate new column value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291589#M88073</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Caveat&lt;/STRONG&gt;  Non-&lt;CODE&gt;streamstats&lt;/CODE&gt; code assumes the data is in &lt;CODE&gt;col_1&lt;/CODE&gt; order ... and the records within any given value in &lt;CODE&gt;col_1&lt;/CODE&gt; are in some determinate order ... like the data in the example.  &lt;/P&gt;

&lt;P&gt;When data is in that order, &lt;CODE&gt;reset_on_change=true&lt;/CODE&gt; has no net effect on the &lt;CODE&gt;streamstats&lt;/CODE&gt; command.  On the other hand, when data is NOT in &lt;CODE&gt;col_1&lt;/CODE&gt; order, &lt;CODE&gt;reset_on_change=true&lt;/CODE&gt; causes a reset of the stats whenever any of the keys change.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 16:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-generate-a-search-to-calculate-new-column-value/m-p/291589#M88073</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-23T16:02:05Z</dc:date>
    </item>
  </channel>
</rss>

