<?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 compare results and assign values from Lookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295836#M89277</link>
    <description>&lt;P&gt;There were typos for both bracket and extra double qoutes. Fixed now. &lt;BR /&gt;
So when you run this, you get wrong values for LRange and HRange columns??&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search giving results with  fields SName, Marks
 | join max=100 [| inputlookup stu_marks | table LRange, HRange, Grade]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Feb 2018 19:21:52 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-02-15T19:21:52Z</dc:date>
    <item>
      <title>How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295829#M89270</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;

&lt;P&gt;Splunk beginner here!! Just trying to do something simple. I have a list of students being obtained from a simple splunk query with their respective marks. For example, a small sample of my current output - &lt;BR /&gt;
SName, Marks&lt;BR /&gt;
Neymar, 87&lt;BR /&gt;
Ronaldo, 92&lt;BR /&gt;
Messi, 98&lt;/P&gt;

&lt;P&gt;Now, I have a lookup table which has a range of marks and the respective grade. Lookup table format - &lt;BR /&gt;
LRange, HRange, Grade&lt;BR /&gt;
95, 100, A&lt;BR /&gt;
90, 95, B&lt;BR /&gt;
85, 90, C&lt;/P&gt;

&lt;P&gt;My objective is to compare and assign each student an appropriate grade. For example, Neymar has 87 marks so he will fall under greater than 85 and less 90, so 'C'. Want my final result to be displayed as follows - &lt;BR /&gt;
Sname, Marks, Grade&lt;BR /&gt;
Neymar, 87, C&lt;BR /&gt;
Ronaldo, 92, B&lt;BR /&gt;
Messi, 98, A&lt;/P&gt;

&lt;P&gt;The query I wrote is which doesn't work - &lt;BR /&gt;
..basic query.. &lt;CODE&gt;|inputlookup stu_marks append=t where ("Marks"&amp;gt;="LRange") AND ("Marks"&amp;lt;"HRange") | fields "Grade"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Any help is highly appreciated.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
V&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 16:28:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295829#M89270</guid>
      <dc:creator>dhawanvarun</dc:creator>
      <dc:date>2018-02-15T16:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295830#M89271</link>
      <description>&lt;P&gt;hello there,&lt;/P&gt;

&lt;P&gt;although can be done with lookup, i feel it will be much easier using some eval command.&lt;BR /&gt;
try this search anywhere and use the eval command as you wish:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval data = "Neymar,87 Ronaldo,92 Messi,98"
| makemv delim=" " data
| mvexpand data
| rex field=data "(?&amp;lt;sName&amp;gt;\w+),(?&amp;lt;Mark&amp;gt;\d{1,3})"
| eval Grade = case(Mark&amp;lt;=100 AND Mark&amp;gt;=95,"A",Mark&amp;lt;95 AND Mark&amp;gt;=90,"B",Mark&amp;lt;90 AND Mark&amp;gt;=85,"C")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 17:16:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295830#M89271</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2018-02-15T17:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295831#M89272</link>
      <description>&lt;P&gt;If you really want to keep it dynamic (via lookup), I believe there are two ways. &lt;/P&gt;

&lt;P&gt;Option 1: Join. It'll basically multiply your current student result set with number of rows in your lookup, so if you need to re-consider if both are really high. Below search assumes your lookup has less than 100 entries&lt;/P&gt;

&lt;H1&gt;Fixed typo&lt;/H1&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search giving results with  fields SName, Marks
| join max=100 [| inputlookup stu_marks | table LRange, HRange, Grade]
| eval Grade=if( (Marks&amp;gt;=LRange) AND (Marks&amp;lt;HRang), Grade, null())
| where isnotnull(Grade) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Option 2: Dynamically generate eval using lookup data. Works best when number of lookup entries are smaller&lt;/P&gt;

&lt;H1&gt;Fixed typo&lt;/H1&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search giving results with  fields SName, Marks
| eval Grade=[| inputlookup stu_marks | eval search="Marks&amp;gt;=".LRange." AND Marks&amp;lt;".HRange.",\"".Grade."\"," | table search | format "" "" "" "" "" "" | eval search="case(".replace(replace(replace(search,",\"",","),"\\\\",""),"\"\"","").",1=1,\"Unknown\")" | eval search=replace(replace(search,",\s*,",","),"\"Marks","Marks")]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 17:28:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295831#M89272</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T17:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295832#M89273</link>
      <description>&lt;P&gt;Thanks you for replying! I do need to keep lookup, so yes dynamic is the option I am looking at. I ran this and it yielded 'No results found.' which isn't true. Do you know what could be going wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 17:47:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295832#M89273</guid>
      <dc:creator>dhawanvarun</dc:creator>
      <dc:date>2018-02-15T17:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295833#M89274</link>
      <description>&lt;P&gt;There were typos in the query before. I corrected them, can you try again? Also, which one are you trying?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 18:42:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295833#M89274</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T18:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295834#M89275</link>
      <description>&lt;P&gt;I am using Option 1 and I thought the only type was with the If brackets '('. &lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:10:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295834#M89275</guid>
      <dc:creator>dhawanvarun</dc:creator>
      <dc:date>2018-02-15T19:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295835#M89276</link>
      <description>&lt;P&gt;Okay so I noticed something, when I look at the lookup file, I see all the values for LRange and HRange. However, I just used a simple join (removed the eval statement from your example) and all I can see is 0s and 1s in HRange and LRange. &lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:17:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295835#M89276</guid>
      <dc:creator>dhawanvarun</dc:creator>
      <dc:date>2018-02-15T19:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295836#M89277</link>
      <description>&lt;P&gt;There were typos for both bracket and extra double qoutes. Fixed now. &lt;BR /&gt;
So when you run this, you get wrong values for LRange and HRange columns??&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search giving results with  fields SName, Marks
 | join max=100 [| inputlookup stu_marks | table LRange, HRange, Grade]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:21:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295836#M89277</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-15T19:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare results and assign values from Lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295837#M89278</link>
      <description>&lt;P&gt;My bad, I just realized what I was doing wrong. I had removed the max statement instead of giving max=0. Thank you somesoni2! It works!!!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 22:43:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-results-and-assign-values-from-Lookup/m-p/295837#M89278</guid>
      <dc:creator>dhawanvarun</dc:creator>
      <dc:date>2018-02-15T22:43:22Z</dc:date>
    </item>
  </channel>
</rss>

