<?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 Why can't I use my lookup command after stats command in my search string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-I-use-my-lookup-command-after-stats-command-in-my/m-p/315035#M94320</link>
    <description>&lt;P&gt;I am trying to use stats command to display data organized by &lt;CODE&gt;My_Field&lt;/CODE&gt; where &lt;CODE&gt;My_Field&lt;/CODE&gt; is populated by running &lt;CODE&gt;lookup my_lookup_script username AS user&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;Here's the example of the search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats STUFF by My_Field | lookup my_lookup_script username AS user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My problem is that &lt;CODE&gt;My_Field&lt;/CODE&gt; is not populated for the stats command to use because the lookup command happens after the stats command. I tried simply running the lookup BEFORE the stats command but the lookup needs to run at the end of the search because if it does not then the lookup does not work properly. If the lookup runs before the stats command It gets inconsistent values for &lt;CODE&gt;user&lt;/CODE&gt;. Seems like the lookup has to be at the end so the whole search can finish running and have the correct data in &lt;CODE&gt;user&lt;/CODE&gt; for the script to use.&lt;/P&gt;

&lt;P&gt;How can I have the lookup run after that stats command to where the stats command can use the &lt;CODE&gt;My_Field&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2017 18:41:59 GMT</pubDate>
    <dc:creator>jcorkey</dc:creator>
    <dc:date>2017-08-31T18:41:59Z</dc:date>
    <item>
      <title>Why can't I use my lookup command after stats command in my search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-I-use-my-lookup-command-after-stats-command-in-my/m-p/315035#M94320</link>
      <description>&lt;P&gt;I am trying to use stats command to display data organized by &lt;CODE&gt;My_Field&lt;/CODE&gt; where &lt;CODE&gt;My_Field&lt;/CODE&gt; is populated by running &lt;CODE&gt;lookup my_lookup_script username AS user&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;Here's the example of the search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats STUFF by My_Field | lookup my_lookup_script username AS user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My problem is that &lt;CODE&gt;My_Field&lt;/CODE&gt; is not populated for the stats command to use because the lookup command happens after the stats command. I tried simply running the lookup BEFORE the stats command but the lookup needs to run at the end of the search because if it does not then the lookup does not work properly. If the lookup runs before the stats command It gets inconsistent values for &lt;CODE&gt;user&lt;/CODE&gt;. Seems like the lookup has to be at the end so the whole search can finish running and have the correct data in &lt;CODE&gt;user&lt;/CODE&gt; for the script to use.&lt;/P&gt;

&lt;P&gt;How can I have the lookup run after that stats command to where the stats command can use the &lt;CODE&gt;My_Field&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 18:41:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-I-use-my-lookup-command-after-stats-command-in-my/m-p/315035#M94320</guid>
      <dc:creator>jcorkey</dc:creator>
      <dc:date>2017-08-31T18:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't I use my lookup command after stats command in my search string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-can-t-I-use-my-lookup-command-after-stats-command-in-my/m-p/315036#M94321</link>
      <description>&lt;P&gt;You are telling us your conclusions rather than your business requirements.  Here's a total stab in the dark.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search | stats STUFF by user  | lookup my_lookup_script username AS user | stats MORESTUFF  by My_Field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If that is not the strategy that you are looking for, then explain the following things - &lt;/P&gt;

&lt;P&gt;1)  what is in the raw fields to be aggregated&lt;BR /&gt;
2) what is the actual field being looked up, and the output fields&lt;BR /&gt;
3) what happens when you put the lookup before the first stats, and why do you think that is incorrect.&lt;/P&gt;

&lt;P&gt;One other thing you can check first - is the capitalization of user field values consistently the same as are in the lookup table?  If not, consider using &lt;CODE&gt;upper()&lt;/CODE&gt; or &lt;CODE&gt;lower()&lt;/CODE&gt; to make it so.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 19:59:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-can-t-I-use-my-lookup-command-after-stats-command-in-my/m-p/315036#M94321</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-31T19:59:28Z</dc:date>
    </item>
  </channel>
</rss>

