<?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: Filtering data based on results of another sub-query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410230#M172796</link>
    <description>&lt;P&gt;In your original search &lt;CODE&gt;| inputlookup uao0nqok.csv &lt;BR /&gt;
 | where read_seconds &amp;gt; 0 | table read_seconds, count_records&lt;/CODE&gt;  do you have value expected values?  . The search NOT is only excluding the users in exclude.csv to that of original file. So, all the columns in your original search/CSV should be available for you.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 16:13:45 GMT</pubDate>
    <dc:creator>lakshman239</dc:creator>
    <dc:date>2019-02-27T16:13:45Z</dc:date>
    <item>
      <title>Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410223#M172789</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;

&lt;P&gt;I have a query about sub-queries. I've searched this forum for a while and tried a few different things but nothing seems to give me the desired result.&lt;/P&gt;

&lt;P&gt;I am doing analysis on data within a csv file. Eventually, I need to calculate the average of a column in this csv but only on SOME records. I have a sub-query which tells me all the users (field name is "user_only") whose records I want to exclude from the average calculation. The sub-query is also on the same csv file.&lt;/P&gt;

&lt;P&gt;So, what I need is something that does: &lt;STRONG&gt;where user_only is NOT IN (...a list of alphanumeric identifiers)&lt;/STRONG&gt;....&lt;/P&gt;

&lt;P&gt;Here is a screenshot showing my current code, shows where in the code my sub-query is and also shows separately that the sub-query does give some results:&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/6622iF4B06150A9876DC2/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;Here is the current search query. Would appreciate any help you can provide!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup uao0nqok.csv 
| where read_seconds &amp;gt; 0
| eval campaign_delivery = substr(custom_type,len(custom_type)-7,8)
| eval user_only = substr(custom_type,0,17)  
| where user_only NOT in 
       [| inputlookup uao0nqok.csv 
        | where read_seconds &amp;gt; 0
        | eval user_only = substr(custom_type,0,17)  
        | eval first_char = substr(custom_type,0,1)
        | where first_char = "X" or first_char = "Y"  
        | eval goodTiming = if(read_seconds != "20", 1, 0)
        | stats max(goodTiming) as goodTiming sum(read_seconds) as read_seconds count as count by user_only
        | search goodTiming=0
        | fields user_only ]

| lookup "ERT_Campaign_mapping.csv" "Campaign Subgroup ID" as campaign_delivery OUTPUT "Campaign Subgroup Name", "Email Sent Date"
| stats sum(read_seconds) as read_seconds sum(count) as count_records by "Campaign Subgroup Name", campaign_delivery, "Email Sent Date"
| eval avg = read_seconds / count_records
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 13:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410223#M172789</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2019-02-27T13:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410224#M172790</link>
      <description>&lt;P&gt;One option would be to use 2 lookups &lt;BR /&gt;
- &lt;CODE&gt;| inputlookup uao0nqok.csv  | put your search here to exclude your users | outputlookup uao0nqok_updated.csv  . Then you can run your first search against this new lookup&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;would this be ok?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:33:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410224#M172790</guid>
      <dc:creator>lakshman239</dc:creator>
      <dc:date>2019-02-27T14:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410225#M172791</link>
      <description>&lt;P&gt;Did you try replacing&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where user_only NOT in 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search NOT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:52:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410225#M172791</guid>
      <dc:creator>knielsen</dc:creator>
      <dc:date>2019-02-27T14:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410226#M172792</link>
      <description>&lt;P&gt;Thanks @lakshman239 , I can try it. I now have the exclusion ids in a new file (just ids not full records) but I still don't know the best way to say exclude the records for these user ids. Don't think my NOT in syntax is correct:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup uao0nqok.csv 
| where read_seconds &amp;gt; 0
| eval campaign_delivery = substr(custom_type,len(custom_type)-7,8)
| eval user_only = substr(custom_type,0,17)  
| where user_only NOT in [inputlookup uao0nqok_exclude.csv ]

| lookup "ERT_Campaign_mapping.csv" "Campaign Subgroup ID" as campaign_delivery OUTPUT "Campaign Subgroup Name", "Email Sent Date"
| stats sum(read_seconds) as read_seconds sum(count) as count_records by "Campaign Subgroup Name", campaign_delivery, "Email Sent Date"
| eval avg = read_seconds / count_records
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410226#M172792</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2019-02-27T14:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410227#M172793</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/72750"&gt;@knielsen&lt;/a&gt;. Thanks for responding. I now tried "search NOT" and got some interesting result. First of all, I got a result, which is progress (unfortunately I can't attach a screenshot here but will explain it).&lt;/P&gt;

&lt;P&gt;I get result with these fields:&lt;BR /&gt;
-Campaign Subgroup Name = looks OK&lt;BR /&gt;
-campaign_delivery = looks OK&lt;BR /&gt;
-Email sent date = looks OK&lt;BR /&gt;
-read_seconds = looks OK&lt;BR /&gt;
-count_records = this column is visible but with all blank values. No good&lt;BR /&gt;
-avg = this column is expected but is not visible. &lt;/P&gt;

&lt;P&gt;I believe as "count_records" is blank, my calculation of avg (which is read_seconds divided by count_records) is not coming through.&lt;/P&gt;

&lt;P&gt;Any idea why that is the case? THis is my query now - i have moved sub-search to a different csv file. Note - the new csv file only has IDs (field name = user_only) but uao0nqok.csv has all other fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup uao0nqok.csv 
| where read_seconds &amp;gt; 0
| eval campaign_delivery = substr(custom_type,len(custom_type)-7,8)
| eval user_only = substr(custom_type,0,17)  
| search NOT [inputlookup uao0nqok_exclude.csv ]

| lookup "ERT_Campaign_mapping.csv" "Campaign Subgroup ID" as campaign_delivery OUTPUT "Campaign Subgroup Name", "Email Sent Date"
| stats sum(read_seconds) as read_seconds sum(count) as count_records by "Campaign Subgroup Name", campaign_delivery, "Email Sent Date"
| eval avg = read_seconds / count_records
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:27:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410227#M172793</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2020-09-29T23:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410228#M172794</link>
      <description>&lt;P&gt;Pls change where to search&lt;BR /&gt;
    | search NOT [|inputlookup uao0nqok_exclude.csv |fields user_only ]&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:27:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410228#M172794</guid>
      <dc:creator>lakshman239</dc:creator>
      <dc:date>2020-09-29T23:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410229#M172795</link>
      <description>&lt;P&gt;Ok just tried that and I think we are getting close. I am now getting a result but now a couple of columns are missing.&lt;/P&gt;

&lt;P&gt;To calculate average, I need 2 fields: read_seconds and count_records. I see value in read_seconds and that looks right. I see a column count_records but it has blank values. Because of this, my "eval avg = read_seconds / count_records" isn't appearing at all in result.&lt;/P&gt;

&lt;P&gt;Can you see why my count_records is blank?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:30:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410229#M172795</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2020-09-29T23:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410230#M172796</link>
      <description>&lt;P&gt;In your original search &lt;CODE&gt;| inputlookup uao0nqok.csv &lt;BR /&gt;
 | where read_seconds &amp;gt; 0 | table read_seconds, count_records&lt;/CODE&gt;  do you have value expected values?  . The search NOT is only excluding the users in exclude.csv to that of original file. So, all the columns in your original search/CSV should be available for you.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 16:13:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410230#M172796</guid>
      <dc:creator>lakshman239</dc:creator>
      <dc:date>2019-02-27T16:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410231#M172797</link>
      <description>&lt;P&gt;Ok, my initial average query was a bit complicated when I was trying with sub-queries. Now, that I have moved that calculation outside (via outputlookup), I have simplified the main query and now I'm happy with the results. Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 16:39:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410231#M172797</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2019-02-27T16:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on results of another sub-query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410232#M172798</link>
      <description>&lt;P&gt;I have since simplified the average calculation and now I'm happy with the exclusion and results. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 16:40:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-based-on-results-of-another-sub-query/m-p/410232#M172798</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2019-02-27T16:40:59Z</dc:date>
    </item>
  </channel>
</rss>

