<?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 do I calculate a field with another field value from a previous row? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374614#M110107</link>
    <description>&lt;P&gt;Give this a try. Calculation for current row's expected value is done based on prev (previous timesran) and prevchange (change% of previous row)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=*
   | fillnull TimesRan value=1 
   | bucket span=1mon _time 
   | stats sum(TimesRan) as timesran by _time 
   | streamstats current=f window=1 last(timesran) as prev 
   | eval change=if (isnull(prev),1,round((timesran-prev)*100/prev,0))
  | streamstats current=f window=1 last(change) as prevchange
   | eval Expected=prev+(coalesce(prevchange,1)*prev)/100
  | table _time Expected timesran
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Feb 2018 19:34:50 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-02-15T19:34:50Z</dc:date>
    <item>
      <title>How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374606#M110099</link>
      <description>&lt;P&gt;Hello Everyone&lt;/P&gt;

&lt;P&gt;I have a below query that gives me output with 4 fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=*
| fillnull TimesRan value=1 
| bucket span=1mon _time 
| stats sum(TimesRan) as timesran by _time 
| streamstats current=f window=1 last(timesran) as prev 
| eval "Change%"=if (isnull(prev),1,round((timesran-prev)*100/prev,0))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The fields returned are _time (divided by Month), timesran (Number of times Ran), prev (Number of times ran on Previous month), Change%(Percentage difference between current month compared to previous month).&lt;/P&gt;

&lt;P&gt;Now what I need in the output is _time, Expected and timesran.&lt;/P&gt;

&lt;P&gt;The timesran in each row should be calculated with the Change% of previous month and the Expected should be displayed in Current row.&lt;/P&gt;

&lt;P&gt;If I use &lt;CODE&gt;| eval Expected=timesran+(('Change%'*timesran)/100)&lt;/CODE&gt; following the above query, it is using the Change% of the same month and this will not make any sense. So I should be able to calculate the Change% of previous event/row's Change% in this particular eval. How can I do that?&lt;/P&gt;

&lt;P&gt;Below are some sample of my current search query.&lt;/P&gt;

&lt;P&gt;_time   timesran    Change% prev&lt;BR /&gt;
2017-05 77359               1&lt;BR /&gt;&lt;BR /&gt;
2017-06 52663             -32           77359&lt;BR /&gt;
2017-07 43185             -18           52663&lt;BR /&gt;
2017-08 17743               -59         43185&lt;/P&gt;

&lt;P&gt;Please help me on this regard!&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Maria Arokiaraj&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 15:16:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374606#M110099</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-13T15:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374607#M110100</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=*
 | fillnull TimesRan value=1 
 | bucket span=1mon _time 
 | stats sum(TimesRan) as timesran by _time 
 | streamstats current=f window=1 last(timesran) as prev 
 | eval change=if (isnull(prev),1,round((timesran-prev)*100/prev,0))
 | reverse 
 | streamstats current=f window=1 last(change) as prevchange 
 | eval Expected=timesran+((change*timesran)/100)
 | reverse | table _time Expected timesran
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Feb 2018 19:56:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374607#M110100</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-13T19:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374608#M110101</link>
      <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;I am still getting the same old results &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I have added change field in the result table to explain you more in detail.&lt;/P&gt;

&lt;P&gt;_time   Expected                        timesran    change&lt;BR /&gt;
2017-05 78132.59                           77359       1&lt;BR /&gt;
2017-06 35810.84                           52663    -32&lt;BR /&gt;
2017-07 35411.7                                43185    -18&lt;BR /&gt;
2017-08 7274.629999999999          17743    -59&lt;BR /&gt;
2017-09 50664.509999999995          29979    69&lt;BR /&gt;
2017-10 41117.31                            35143    17&lt;BR /&gt;
2017-11 60423.75                            46125   31&lt;BR /&gt;
2017-12 44452.8                                 45360   -2&lt;BR /&gt;
2018-01 116321.6                            72701   60&lt;/P&gt;

&lt;P&gt;In the above table every line's Expected is calculated with the timesran and the same row's change.&lt;BR /&gt;
I need it to be calculated with it's previous row's change.&lt;BR /&gt;
For eg, for 2018-01 row the Expected is 116321.6 because the timesran is calculated with change 60 which is on the same row. It is a change from previous timesran. What I need is, the timesran to be calculated from the previous month's -2. The same way for all other rows. Is it possible in any way?&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Maria Arokiaraj&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 11:31:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374608#M110101</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-14T11:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374609#M110102</link>
      <description>&lt;P&gt;@somesoni2 &amp;amp; everyone&lt;/P&gt;

&lt;P&gt;Is there any way in Splunk to achieve my above requirement? Please help!&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:57:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374609#M110102</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-15T10:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374610#M110103</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;H1&gt;Fixed syntax error&lt;/H1&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=*
  | fillnull TimesRan value=1 
  | bucket span=1mon _time 
  | stats sum(TimesRan) as timesran by _time 
  | streamstats current=f window=1 last(timesran) as prev 
  | eval change=if (isnull(prev),1,round((timesran-prev)*100/prev,0))
 | streamstats current=f window=1 last(change) as prevchange
  | eval Expected=timesran+(coalesce(prevchange,1)*timesran)/100
 | table _time Expected timesran
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 16:57:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374610#M110103</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T16:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374611#M110104</link>
      <description>&lt;P&gt;Hello @somesoni2&lt;/P&gt;

&lt;P&gt;Looks to be a small syntax issue. There was an error ) is missing, hence I added it like in below line.&lt;BR /&gt;
    | eval change=if (isnull(prev),1,round((timesran-prev)*100)/prev,0)) &lt;/P&gt;

&lt;P&gt;Now the error is The arguments to the 'if' function are invalid.&lt;BR /&gt;
I tried to find the root cause but for me everything seems to be proper. Can you find the root cause?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 18:02:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374611#M110104</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-15T18:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374612#M110105</link>
      <description>&lt;P&gt;Try the fixed one.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 18:43:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374612#M110105</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T18:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374613#M110106</link>
      <description>&lt;P&gt;This still doesn't work as expected &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt;.&lt;/P&gt;

&lt;P&gt;_time   Expected    timesran    change&lt;BR /&gt;
2017-05 78132.59    77359   1&lt;BR /&gt;
2017-06 53189.63    52663   -32&lt;BR /&gt;
2017-07 29365.8        43185    -18&lt;BR /&gt;
2017-08 14549.26    17743   -59&lt;BR /&gt;
2017-09 12291.39    29979   69&lt;BR /&gt;
2017-10 59391.67    35143   17&lt;BR /&gt;
2017-11 53966.25    46125   31&lt;BR /&gt;
2017-12 59421.6         45360   -2&lt;BR /&gt;
2018-01 71246.98    72701   60&lt;/P&gt;

&lt;P&gt;The Expected is not calculated with Previous line's Timesran and Percentage. The 2017-05's timesran+(timesran*change/100) should the Expected for 2017-06. 2017-06's  timesran+(timesran*change/100) should be the Expected value for 2017-07 row. Very sorry that I did not explain it clearly in my previous comments &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Please help.&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Maria Arokiaraj&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:04:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374613#M110106</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2020-09-29T18:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374614#M110107</link>
      <description>&lt;P&gt;Give this a try. Calculation for current row's expected value is done based on prev (previous timesran) and prevchange (change% of previous row)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=*
   | fillnull TimesRan value=1 
   | bucket span=1mon _time 
   | stats sum(TimesRan) as timesran by _time 
   | streamstats current=f window=1 last(timesran) as prev 
   | eval change=if (isnull(prev),1,round((timesran-prev)*100/prev,0))
  | streamstats current=f window=1 last(change) as prevchange
   | eval Expected=prev+(coalesce(prevchange,1)*prev)/100
  | table _time Expected timesran
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:34:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374614#M110107</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T19:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate a field with another field value from a previous row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374615#M110108</link>
      <description>&lt;P&gt;You're Awesome @somesoni2. Thanks a lot. It worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 13:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-a-field-with-another-field-value-from-a/m-p/374615#M110108</guid>
      <dc:creator>maria2691</dc:creator>
      <dc:date>2018-02-16T13:41:25Z</dc:date>
    </item>
  </channel>
</rss>

