<?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 excuse a 'foreach' sequentially in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440523#M125261</link>
    <description>&lt;P&gt;@telecomdesign, what are you trying to achieve ? You might not even to use &lt;CODE&gt;foreach&lt;/CODE&gt; in this scenario.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2019 08:24:22 GMT</pubDate>
    <dc:creator>DavidHourani</dc:creator>
    <dc:date>2019-06-25T08:24:22Z</dc:date>
    <item>
      <title>How to excuse a 'foreach' sequentially</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440520#M125258</link>
      <description>&lt;P&gt;Hello here is an example of the code I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="Test"

 | append [search (type="1")

| stats   distinct_count(ID) as r by  type

 | eval ID1=(100.00-r)]


 | append [search (type="2")

| stats   distinct_count(ID) as r by  type

 | eval ID2=(100.00-r)]


 | append [search (type="3")

| stats   distinct_count(ID) as r by  type

 | eval ID3=(100.00-r)]


 |eval Min_all=101,Min_Comp=0, Min_Var1=ID1, Min_Var2=ID2, Min_Var3=ID3  

 |foreach Min_Var* [|eval Min_Comp=('&amp;lt;&amp;gt;')

     | eval Min_all=if(

        Min_Comp&amp;lt;Min_all,

            Min_Comp,

            Min_all) ]        
| stats first(ID1),first(ID2),first(ID3), first(Min_all), first(Min_Comp) by type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a problem with the execution of the "foreach" it always execute at the begining of the code and does not wait that the Min value have a value. &lt;BR /&gt;
Do you know how to do it sequentialy ?&lt;/P&gt;

&lt;P&gt;Thanks !&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 15:17:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440520#M125258</guid>
      <dc:creator>telecomdesign</dc:creator>
      <dc:date>2019-06-24T15:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to excuse a 'foreach' sequentially</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440521#M125259</link>
      <description>&lt;P&gt;I would be great if you can post what output you're getting before and after the foreach command and highlighting where is problem is. With much information here, I would suggest this&lt;/P&gt;

&lt;P&gt;replace below line in your search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Min_all=101,Min_Comp=0, Min_Var1=ID1, Min_Var2=ID2, Min_Var3=ID3 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval Min_all=101,Min_Comp=0 | eventstats values(ID1) as Min_Var1 , values(ID2) as Min_Var2, values(ID3) as Min_Var3 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jun 2019 19:23:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440521#M125259</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-06-24T19:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to excuse a 'foreach' sequentially</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440522#M125260</link>
      <description>&lt;P&gt;Thank you, your answer was so usefull !&lt;BR /&gt;
Now we want to have result by serial. So we have now 3 different values, and we would like to execute the foreach for each value. &lt;/P&gt;

&lt;P&gt;Here the code' example &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index="Test"

      | append [search (type="1")

     | stats   distinct_count(ID) as r by  Serial

      | eval ID1=(100.00-r)]


      | append [search (type="2")

     | stats   distinct_count(ID) as r by  Serial

      | eval ID2=(100.00-r)]


      | append [search (type="3")

     | stats   distinct_count(ID) as r by  Serial

      | eval ID3=(100.00-r)]


      |eval Min_all=101,Min_Comp=0  
 | eventstats values(ID1) as Min_Var1 , values(ID2) as Min_Var2, values(ID3) as Min_Var3 

      |foreach Min_Var* [|eval Min_Comp=('&amp;lt;&amp;gt;')

          | eval Min_all=if(

             Min_Comp&amp;lt;Min_all,

                 Min_Comp,

                 Min_all) ]        

     | stats first(ID1),first(ID2),first(ID3), first(Min_all), first(Min_Comp) by Serial
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;example of our result&lt;/P&gt;

&lt;P&gt;ID1           ID2           ID3          Min_all          Min_comp&lt;BR /&gt;
95            90             96            101                100&lt;BR /&gt;
96            91             92             101                100&lt;BR /&gt;
98            95             97             101                 100 &lt;/P&gt;

&lt;P&gt;Min_all and Min_comp aren't right so we would like execute the foreach by line do you know how could we do it ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440522#M125260</guid>
      <dc:creator>telecomdesign</dc:creator>
      <dc:date>2020-09-30T01:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to excuse a 'foreach' sequentially</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440523#M125261</link>
      <description>&lt;P&gt;@telecomdesign, what are you trying to achieve ? You might not even to use &lt;CODE&gt;foreach&lt;/CODE&gt; in this scenario.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 08:24:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440523#M125261</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-06-25T08:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to excuse a 'foreach' sequentially</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440524#M125262</link>
      <description>&lt;P&gt;I will say it again.  Don't focus on what doesn't work or what commands do what.  Just tell us what you are trying to do and do it like this:&lt;BR /&gt;
Show a set of sample events, then show a mockup of the desire result.  THEN add some description of the steps (pseudocode, not SPL) of how to get from events to result.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:21:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-excuse-a-foreach-sequentially/m-p/440524#M125262</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-01T18:21:01Z</dc:date>
    </item>
  </channel>
</rss>

