<?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: Looping a &amp;quot;forecasting&amp;quot; column using stats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465184#M131070</link>
    <description>&lt;P&gt;Nice.  You gave him the answer in the most efficient way whereas I gave him the answer in the method that he was describing.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2019 17:41:29 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-12-12T17:41:29Z</dc:date>
    <item>
      <title>Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465179#M131065</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I just cannot wrap my head around how splunk does looping. &lt;BR /&gt;
Below is what I'm currently trying to do:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8084i2CF0FCBA820FA281/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Percentage is calculated as (met / score) * 100.&lt;BR /&gt;
In my "forecast" column, I need to show how many more I need to score to pass the minimum percentage of 90% (assuming that every ticket scored in the future will be met). &lt;/P&gt;

&lt;P&gt;In order to solve this, I need to somehow generate a loop that produces this output:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8085iDEBD57529CD4E83E/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Through this loop, I have determined that I needed a score of 15 more (due to 15 iterations) to pass the minimum of 90%.&lt;/P&gt;

&lt;P&gt;Now I'm trying to produce this table using SPL but I have no idea where to start.&lt;BR /&gt;
Assuming I'm able to generate the table, how can I "delete" the generated table and simply add '15' to my forecast column?&lt;/P&gt;

&lt;P&gt;Any help would be greatly  appreciated.&lt;/P&gt;

&lt;P&gt;Thanks. &lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 10:23:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465179#M131065</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-12-12T10:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465180#M131066</link>
      <description>&lt;P&gt;SPL is not a procedural language.  It has looping commands ( &lt;CODE&gt;foreach&lt;/CODE&gt; and &lt;CODE&gt;map&lt;/CODE&gt; ), but they don't do what you require.  In addition, there is no way to delete results once you create them.&lt;/P&gt;

&lt;P&gt;I think there is a mathematical way to compute 'forecast' without having to count iterations.  According to Google, for &lt;CODE&gt;(x-2/x)*100=90&lt;/CODE&gt; x equals 20.  More generally, for &lt;CODE&gt;(x-y/x)*100=90&lt;/CODE&gt; x is 10y.  In this case, the number of iterations would be &lt;CODE&gt;(10*missed)-score&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:23:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465180#M131066</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-12-12T13:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465181#M131067</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You could use the below method to calculate the no of iterations.&lt;BR /&gt;
Need to supply the increment value for the score. I am taking it as one here.&lt;BR /&gt;
Please test and let us know.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   |makeresults
   |eval _raw="
   score,met,missed,percentage,minimum,forecast
   5,3,2,60,90"
   |multikv forceheader=1
   |rename COMMENT AS "The below  code is the actual query" 

   |eval required_score=(100*missed)/(100-minimum)
   |eval increment=1
   |eval forecast=ceil((required_score-score)/increment)
   |table score,met,missed,percentage,minimum,required_score,forecast
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 15:52:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465181#M131067</guid>
      <dc:creator>dindu</dc:creator>
      <dc:date>2019-12-12T15:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465182#M131068</link>
      <description>&lt;P&gt;I am assuming that your raw data just has a &lt;CODE&gt;met&lt;/CODE&gt; or &lt;CODE&gt;missed&lt;/CODE&gt; indicator.  If so, do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
|  eval _raw="metORmissed
missed
missed
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met
met"
| multikv forceheader=1
| streamstats count AS _serial
| eval _time = _time + _serial
| fields - linecount
| sort 0 - _time

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| reverse
| streamstats count AS score count(eval(metORmissed="met")) AS met count(eval(metORmissed="missed")) AS missed
| eval minimum=90
| eval pct = 100 * met / (met + missed)

| where pct &amp;gt;= 90
| head 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:18:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465182#M131068</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-12T17:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465183#M131069</link>
      <description>&lt;P&gt;I think my other answer was missing the mark.  I think that this one is really what you need:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="score=5, met=3 missed=2,pct=60"
| kv

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval predicted_events = 0, count=0
| append [ |makeresults | eval predicted_events=mvrange(1,100) | mvexpand predicted_events | streamstats count ]
| filldown score met missed
| eval score = score + count, met = met + count
| fields - count
| eval pct = 100 * met / (met + missed)
| where pct &amp;gt;= 90
| head 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:38:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465183#M131069</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-12T17:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465184#M131070</link>
      <description>&lt;P&gt;Nice.  You gave him the answer in the most efficient way whereas I gave him the answer in the method that he was describing.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:41:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465184#M131070</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-12T17:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465185#M131071</link>
      <description>&lt;P&gt;Thanks, Woodcock!!!&lt;BR /&gt;
I am glad to be mentioned by you.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 18:55:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465185#M131071</guid>
      <dc:creator>dindu</dc:creator>
      <dc:date>2019-12-12T18:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465186#M131072</link>
      <description>&lt;P&gt;Thank you. I have learned a lot from this answer. &lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 06:08:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465186#M131072</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-12-13T06:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465187#M131073</link>
      <description>&lt;P&gt;Could you please explain why this works? Did you get the formula from somewhere? I really should have paid more attention in math class. &lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 06:22:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465187#M131073</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-12-13T06:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Looping a "forecasting" column using stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465188#M131074</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;it was similar to an arithmetic progression.&lt;BR /&gt;
I just solved the equation and tested it for a few values.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 14:17:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-a-quot-forecasting-quot-column-using-stats/m-p/465188#M131074</guid>
      <dc:creator>dindu</dc:creator>
      <dc:date>2019-12-13T14:17:46Z</dc:date>
    </item>
  </channel>
</rss>

