<?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: Complex search with set operation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195941#M56502</link>
    <description>&lt;P&gt;Thanks, the 'big table' concept got it for me. I had tried the separate searches, but didn't understand the blank entries in the results after the appends, but when putting that into a table, I worked it out.&lt;/P&gt;

&lt;P&gt;You've been a great help, you've got me over a mental hurdle. Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2014 02:22:38 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2014-01-07T02:22:38Z</dc:date>
    <item>
      <title>Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195933#M56494</link>
      <description>&lt;P&gt;I have 3 sourcetypes representing learners, courses and course completion details&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;learners - the learner details
catalog - the total course catalog for each learner
completions - the course completions for the learer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Amongst other fields, &lt;/P&gt;

&lt;P&gt;"learners" contains Username, Name&lt;BR /&gt;
"catalog" contains Username, Asset_Title&lt;BR /&gt;
"completions" contains Username, Asset_Title&lt;/P&gt;

&lt;P&gt;I want to produce a report showing each learner, the total number of courses in their catalog and the total number of courses they have completed along with a % completion. The following search &lt;STRONG&gt;&lt;EM&gt;almost&lt;/EM&gt;&lt;/STRONG&gt; gets there.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| set intersect [ search sourcetype=catalog* | fields Asset_Title, Username | fields - _* ] [ search sourcetype=completions* | fields Asset_Title, Username | fields - _* ] | eventstats dc(Asset_Title) as Count by Username | join Username [ search sourcetype=learners* ] | stats Count by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I can't see how to get the total courses from the catalog for each learner to be retained as a field after the set operation, so I can add that as a Total field and calculate the %.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:34:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195933#M56494</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-09-28T15:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195934#M56495</link>
      <description>&lt;P&gt;Why not this? It seems much more simple&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Username=* 
| stats count(eval(match(sourcetype,"catalog.*"))) as Catalog  count(eval(match(sourcetype,"completion.*"))) as Completed first(Name) as Name by Username
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Although it looks like you expect to see duplicate Asset_Titles, so maybe this would work better&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=learners
| append [ search sourcetype=catalog | stats dc(Asset_Title) as CatalogCount by Username ]
| append [ search sourcetype=completions | stats dc(Asset_Title) as CompletionCount by Username ]
| stats sum(CatalogCount) as Total sum(CompletionCount) as Completed first(Name) as Name by Username
| eval PercentCompleted=round(Completed * 100 / Total, 2)
| table Name Username Completed Total PercentCompleted
| sort Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think either of these will run faster and be less complex than all the joins...&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 05:37:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195934#M56495</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-06T05:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195935#M56496</link>
      <description>&lt;P&gt;Thanks iguinn!  The first didn't work - I actually have a couple of variants of sourcetype, i.e. I have completions_standard and completions_script, so I normally use completions* but the stats command doesn't like count(sourcetype=completions*).&lt;/P&gt;

&lt;P&gt;However, the second seems to work - although it needed the 'search' in the append subsearch, i.e. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;append [ search sourcetype...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:35:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195935#M56496</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-09-28T15:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195936#M56497</link>
      <description>&lt;P&gt;Sorry about the typo in the &lt;CODE&gt;append&lt;/CODE&gt; command - I corrected my answer. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 08:11:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195936#M56497</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-06T08:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195937#M56498</link>
      <description>&lt;P&gt;Bah - I just figured out another problem with my first search...&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 22:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195937#M56498</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-06T22:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195938#M56499</link>
      <description>&lt;P&gt;Hi Iguinn, one thing I don't understand about Splunk is how the append works to append the CatalogCount and CompletionCount values to the right learner result. How is it that the CatalogCount by Username will get correctly associated with the relevant Username record from the sourcetype=learners.&lt;/P&gt;

&lt;P&gt;I'm still missing something fundamental in how the search pipeline works I think. Can you clarify how this works.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 23:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195938#M56499</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2014-01-06T23:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195939#M56500</link>
      <description>&lt;P&gt;Try running each of these searches separately:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=catalog | stats dc(Asset_Title) as CatalogCount by Username&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=completions | stats dc(Asset_Title) as CompletionCount by Username&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=learners | table Username Name&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Then think about how you would combine these into one big table - maintaining a row for each event (some columns would be empty).&lt;BR /&gt;
Now, with your table, imagine doing the following &lt;CODE&gt;stats&lt;/CODE&gt; command:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;stats sum(CatalogCount) as Total sum(CompletionCount) as Completed first(Name) as Name by Username&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;which creates a single row for each Username&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 23:57:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195939#M56500</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-06T23:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195940#M56501</link>
      <description>&lt;P&gt;Hopefully that helps. Or just run the first line of the search. Then run the first two lines of the search and see what happens. Then run the first 3 lines of the search... etc. etc.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2014 23:58:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195940#M56501</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-01-06T23:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Complex search with set operation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195941#M56502</link>
      <description>&lt;P&gt;Thanks, the 'big table' concept got it for me. I had tried the separate searches, but didn't understand the blank entries in the results after the appends, but when putting that into a table, I worked it out.&lt;/P&gt;

&lt;P&gt;You've been a great help, you've got me over a mental hurdle. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2014 02:22:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Complex-search-with-set-operation/m-p/195941#M56502</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2014-01-07T02:22:38Z</dc:date>
    </item>
  </channel>
</rss>

