<?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 anqRe: Subquery in an else statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529774#M149655</link>
    <description>&lt;P&gt;Thanks for your quick reply and thanks for the return tip...I'm a SPLUNK beginner. Well it seems though to not be working.&lt;/P&gt;&lt;P&gt;It's because I lose the row that I want to get in the else statement since it has a different &lt;STRONG&gt;model_name&lt;/STRONG&gt; and it is lost with the &lt;STRONG&gt;join&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2020 15:17:51 GMT</pubDate>
    <dc:creator>frozenpy</dc:creator>
    <dc:date>2020-11-17T15:17:51Z</dc:date>
    <item>
      <title>Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529754#M149648</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I trying to perform a subquery on an else statement, I believe that the way I'm trying to do it is not right. I searched a bit over the internet but I couldn't find a way of doing it.&lt;/P&gt;&lt;P&gt;My problem is as follows, I have two inputlookups, I want to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Read from first lookup extract a value name associated to a maximum in another column (&lt;STRONG&gt;done&lt;/STRONG&gt;)&lt;/LI&gt;&lt;LI&gt;Join over that column (&lt;STRONG&gt;&lt;EM&gt;model_name&lt;/EM&gt;&lt;/STRONG&gt;) with the second inputlookup and check whether evaluation metric is superiror to a given treshold keep the &lt;STRONG&gt;&lt;EM&gt;model_name&lt;/EM&gt;&lt;/STRONG&gt;. (&lt;STRONG&gt;done&lt;/STRONG&gt;)&lt;/LI&gt;&lt;LI&gt;Else query the second inputlookup to find model_name associated with maximum value. (&lt;STRONG&gt;my problem is here...how to write a subquery in an else statement&lt;/STRONG&gt;)&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here's a not working code in the else statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup model_evaluation.csv 
| eventstats max(evaluation_metric) as maxf 
| eval maxf=tonumber(maxf) 
| eval evaluation_metric=tonumber(evaluation_metric) 
| where  evaluation_metric&amp;gt;=maxf  
| dedup maxf
| rename evaluation_metric as training_score
| table model_name training_score

| join type=inner model_name

[|inputlookup model_evaluation_month.csv
| eval good_model_name = case (evaluation_metric &amp;gt; 0.95, model_name, 1=1, [search | eventstats max(evaluation_metric) as maxf | eval maxf=tonumber(maxf) | eval evaluation_metric=tonumber(evaluation_metric) | where  evaluation_metric&amp;gt;=maxf |dedup maxf | return model_name])
| table *, good_model_name
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 13:39:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529754#M149648</guid>
      <dc:creator>frozenpy</dc:creator>
      <dc:date>2020-11-17T13:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529766#M149652</link>
      <description>&lt;P&gt;By default, the &lt;FONT face="courier new,courier"&gt;return&lt;/FONT&gt; command returns a result in the form of "field=value", which doesn't make sense in a case statement.&amp;nbsp; Try &lt;FONT face="courier new,courier"&gt;return $model_name&lt;/FONT&gt;, which should return just the value.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:44:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529766#M149652</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-17T14:44:53Z</dc:date>
    </item>
    <item>
      <title>anqRe: Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529774#M149655</link>
      <description>&lt;P&gt;Thanks for your quick reply and thanks for the return tip...I'm a SPLUNK beginner. Well it seems though to not be working.&lt;/P&gt;&lt;P&gt;It's because I lose the row that I want to get in the else statement since it has a different &lt;STRONG&gt;model_name&lt;/STRONG&gt; and it is lost with the &lt;STRONG&gt;join&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 15:17:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529774#M149655</guid>
      <dc:creator>frozenpy</dc:creator>
      <dc:date>2020-11-17T15:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: anqRe: Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529785#M149662</link>
      <description>&lt;P&gt;Run the subsearch by itself to confirm it returns the expected results.&amp;nbsp; Next, run the enclosing search using the output from the subsearch, for example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup model_evaluation_month.csv
| eval good_model_name = case (evaluation_metric &amp;gt; 0.95, model_name, 1=1, "foo")
| table *, good_model_name&lt;/LI-CODE&gt;&lt;P&gt;and confirm that returns the expected results.&amp;nbsp; Once that works, then it's time to attempt the join.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider using &lt;FONT face="courier new,courier"&gt;append&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;join&lt;/FONT&gt; since the latter can be inefficient.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 16:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529785#M149662</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-17T16:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: anqRe: Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529881#M149690</link>
      <description>&lt;P&gt;I finally made it to work, first it was the &lt;STRONG&gt;evals&amp;nbsp;&lt;/STRONG&gt;made before the join occurs and then it was multiple if statement that needed to be checked. Bellow the code if that might someday help anyone and thank you for your replies&amp;nbsp;&lt;A href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957" target="_self"&gt;&lt;SPAN class="login-bold"&gt;richgalloway&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="line"&gt;|inputlookup model_evaluation.csv | rename evaluation_metric as training_score | table model_name training_score&lt;/SPAN&gt;

&lt;SPAN class="line"&gt;	| join type=inner model_name&lt;/SPAN&gt;

&lt;SPAN class="line"&gt;	[|inputlookup model_evaluation_month.csv]&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eventstats max(training_score) as max_training&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eventstats max(evaluation_metric) as max_evaluation&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eval model_max_evaluation =  if(tonumber(evaluation_metric) == tonumber(max_evaluation), model_name, "void")&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eval good_model_name = if(training_score == max_training and evaluation_metric &amp;gt;= 0.94, model_name, model_max_evaluation)&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| dedup good_model_name&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| where like(training_score,  "%".max_training."%") OR NOT like(good_model_name, "void")&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eventstats count(model_name) as count_lines&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| eval model_to_keep = if(count_lines &amp;gt; 1, if(training_score == max_training and evaluation_metric &amp;gt;= 0.94, "True", "False"), "None")&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| search model_to_keep IN ("True", "None")&lt;/SPAN&gt;
&lt;SPAN class="line"&gt;	| table model_name&lt;/SPAN&gt;
&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 11:01:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529881#M149690</guid>
      <dc:creator>frozenpy</dc:creator>
      <dc:date>2020-11-18T11:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery in an else statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529905#M149701</link>
      <description>&lt;P&gt;If your problem is resolved, then please click the "Accept as Solution" button to help future readers.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 13:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subquery-in-an-else-statement/m-p/529905#M149701</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-18T13:23:00Z</dc:date>
    </item>
  </channel>
</rss>

