<?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: Issues adding columns from a subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462885#M130524</link>
    <description>&lt;P&gt;skoelpin, what do you mean by "flag your results"?  Can you point me at an example?&lt;/P&gt;</description>
    <pubDate>Thu, 28 May 2020 11:40:11 GMT</pubDate>
    <dc:creator>gavinsopra</dc:creator>
    <dc:date>2020-05-28T11:40:11Z</dc:date>
    <item>
      <title>Issues adding columns from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462882#M130521</link>
      <description>&lt;P&gt;My first subsearch – and its not going well.  I have two queries I need to combine to get a single results table.&lt;/P&gt;

&lt;P&gt;My first query finds how many changes there have been and when the most recent change occurred (events in my data will have a ‘no_of_changes' field which is an integer value)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=syncserver sync_job_name=Purchasing sync_job_name!="Stage 1" no_of_changes!=0 
| stats sum(no_of_changes) AS "No. of Changes" latest(_time) AS "Last Change" by sync_group_name 
| convert ctime("Last Change")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which produces the “Query 1 results table” below&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/290851-subsearch-table1-and-2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Then I have  a second query, which is very similar to the first, but all I really want from it is the date/time of the last event for each ‘syncGroup’.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=syncserver sync_job_name=Purchasing sync_job_name!="Stage 1" | stats sum(no_of_changes) AS "No. of Changes" latest(_time) AS "Last Run" by sync_group_name 
| convert ctime("Last Run")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which produces the “Query 2 results table” above.&lt;BR /&gt;
Note that ‘SyncGroup03’ does not appear in the first set of results as there where no changes in the selected time period.&lt;BR /&gt;
The table I want to produce combines these two sets of results as in “Desired results table” below&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/290852-subsearch-table2-and-4.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;So I have tried the following query which makes my first query a subsearch of the second query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=syncserver sync_job_name=Purchasing sync_job_name!="Stage 1" 
| stats sum(no_of_changes) latest(_time) AS “lastRun” by sync_group_name 
| appendcols 
    [ search index=syncserver sync_job_name=Purchasing sync_job_name!="Stage 1" no_of_changes!=0 
    | stats latest(_time) AS lastChange by sync_group_name] 
| convert ctime(lastChange) 
| rename lastChange AS "Last Change" lastRun AS "Last Run" sum(no_of_changes) AS "No. of Changes" 
| table sync_group_name "No. of Changes" "Last Change" "Last Run"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which isn’t what I was hoping for (see “Actual results table” above)&lt;/P&gt;

&lt;P&gt;So the “Last Run” column isn’t getting populated and the time for “Last Change” on ‘SyncGroup04” (04/14/2020 03:05:37) has appeared against SyncGroup03.&lt;/P&gt;

&lt;P&gt;I also had to use different field names in the query as Splunk complained about the presence of ‘last’ in ‘latest(_time) AS "Last Change"’ once the subsearch was added.&lt;/P&gt;

&lt;P&gt;Can someone help me with this?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:32:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462882#M130521</guid>
      <dc:creator>gavinsopra</dc:creator>
      <dc:date>2020-09-30T05:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issues adding columns from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462883#M130522</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; index=syncserver sync_job_name=Purchasing sync_job_name!="Stage 1"
 | stats sum(no_of_changes) AS "No. of Changes" latest(eval(if(no_of_changes!=0,_time,NULL))) AS "Last Change" latest(_time) AS "Last Run" by sync_group_name 
 | convert ctime("Last Change") ctime("Last Run")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How about doing a search together?&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:12:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462883#M130522</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-05-27T19:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issues adding columns from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462884#M130523</link>
      <description>&lt;P&gt;Why are you subsearching on the same dataset? Don't do this. Search against the data set once and flag your results rather than filtering&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:18:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462884#M130523</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2020-05-27T19:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issues adding columns from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462885#M130524</link>
      <description>&lt;P&gt;skoelpin, what do you mean by "flag your results"?  Can you point me at an example?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 11:40:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462885#M130524</guid>
      <dc:creator>gavinsopra</dc:creator>
      <dc:date>2020-05-28T11:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Issues adding columns from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462886#M130525</link>
      <description>&lt;P&gt;Bingo.  That worked nicely,&lt;BR /&gt;
Many thanks&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 11:40:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issues-adding-columns-from-a-subsearch/m-p/462886#M130525</guid>
      <dc:creator>gavinsopra</dc:creator>
      <dc:date>2020-05-28T11:40:35Z</dc:date>
    </item>
  </channel>
</rss>

