<?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 two searches and count multiple fields and values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325883#M97150</link>
    <description>&lt;P&gt;Funny, I don’t remember helping much!  Happy to know even if I had a small part in creating a splunk monster like you though @daljeanis.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2017 23:05:22 GMT</pubDate>
    <dc:creator>jkat54</dc:creator>
    <dc:date>2017-12-08T23:05:22Z</dc:date>
    <item>
      <title>How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325869#M97136</link>
      <description>&lt;P&gt;I have combined data from two searches and want to compare them to identify what is new in the second search, what is removed from the first, and what is persistent across both searches.  My data looks like:&lt;BR /&gt;
asset event search&lt;BR /&gt;
1 a 1st&lt;BR /&gt;
1 a 2nd&lt;BR /&gt;
1 b 1st&lt;BR /&gt;
1 c 2nd&lt;BR /&gt;
I want the results to look like&lt;BR /&gt;
asset event status&lt;BR /&gt;
1 a persistent&lt;BR /&gt;
1 b removed&lt;BR /&gt;
1 c new&lt;/P&gt;

&lt;P&gt;How would I go about doing this?  Im thinking a combination of eval with nested if statements, but really not sure if this is the best approach or how to execute. &lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325869#M97136</guid>
      <dc:creator>glenngermiathen</dc:creator>
      <dc:date>2017-12-08T16:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325870#M97137</link>
      <description>&lt;P&gt;Can you post your searches?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:03:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325870#M97137</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-08T16:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325871#M97138</link>
      <description>&lt;P&gt;Try like this(&lt;STRONG&gt;fixed typo on mvcount&lt;/STRONG&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search with results from both searches
| table asset event search
| stats values(search) as search by asset event
| eval status=case(mvcount(search)=2,"persistent",search="1st","removed",true(),"new")
| table asset event status
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:18:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325871#M97138</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-08T16:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325872#M97139</link>
      <description>&lt;P&gt;My high-level approach to this would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;first search 
| eval from_first=1
| append [ second search  | eval from_second=1 ]
| stats values(from_first) AS from_first, values(from_second) AS from_second BY asset event
| eval status=case(from_first=1 AND from_second=1, "persistent", 
  from_first=1 AND isnull(from_second), "removed", 
  isnull(from_first) AND from_second=1, "new")
| fields - from_first from_second
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There may well be a more efficient way to do it if we analyze your specific search queries. &lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:22:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325872#M97139</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-08T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325873#M97140</link>
      <description>&lt;P&gt;Works great, thanks!  Just a typo on mvcount&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 17:19:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325873#M97140</guid>
      <dc:creator>glenngermiathen</dc:creator>
      <dc:date>2017-12-08T17:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325874#M97141</link>
      <description>&lt;P&gt;Oops. Fixed.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 17:21:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325874#M97141</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-08T17:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325875#M97142</link>
      <description>&lt;P&gt;@elliotproebstel - That would work... and I'll give you some general comments about improving efficiency, since you brought it up.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;In general, you never want to have two searches when one will do.  So this pseudocode...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  first search 
 | eval from_first=1
 | append [ second search  | eval from_second=1 ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...should be replaced whenever possible by this pseudocode... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (first search) OR (second search) 
 | eval from_first=case( this is from the first search, 1)
 | eval from_second=case( this is from the second search, 1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To make searches as efficient as possible, one should always get in the habit of getting rid of all unneeded fields. There aren't any in the example data, but just for good practice, there should be a &lt;CODE&gt;fields&lt;/CODE&gt; command there.  &lt;/P&gt;

&lt;P&gt;There is only going to be a single value or none, so &lt;CODE&gt;values()&lt;/CODE&gt; and &lt;CODE&gt;max()&lt;/CODE&gt; are equivalent.  I tend to use &lt;CODE&gt;max()&lt;/CODE&gt; in that case, because it implicitly guarantees there will not be multiple values, and you don't ever have to look higher in the code to confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (first search) OR (second search) 
 | fields asset event ... plus whatever I need to differentiate between searches
 | eval from_first=case( this is from the first search, 1)
 | eval from_second=case( this is from the second search, 1)
 | stats  max(from_first) as from_first max(from_second) as from_second by asset event 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Technically, you don't have to create the from_* fields there, and since you only want to test existence or not, so you can use a &lt;CODE&gt;count(eval())&lt;/CODE&gt; in the stats instead of creating fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (first search) OR (second search) 
 | fields asset event ... plus whatever I need to differentiate between searches
 | stats  max(eval(test that produces a 1 if first search or null otherwise))) as found_first, 
           max(eval(test that produces a 1 if second search or null otherwise)))  as found_second by asset event 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:00:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325875#M97142</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-12-08T19:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325876#M97143</link>
      <description>&lt;P&gt;Thank you! As usual, @DalJeanis, I learn so much from your feedback. I really appreciate you taking the time to share this.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325876#M97143</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-08T19:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325877#M97144</link>
      <description>&lt;P&gt;@elliotproebstel - Well, I notice you and @kamlesh_vaghela spending a lot of time helping people out, so I decided to invest some time in y'all Dalsplaining whenever I can.  @woodcock and @somesoni2 and @jkat54 and many others did that for me, so I'm passing it on, and I'm sure you will too.&lt;/P&gt;

&lt;P&gt;By the way, get on the Splunk slack channel if you aren't already.  Plenty more good stuff happening there.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:31:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325877#M97144</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-12-08T19:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325878#M97145</link>
      <description>&lt;P&gt;Thanks. I did send in a request for the Splunk slack channel a few days ago, so hopefully I'll get approved soon!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325878#M97145</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-08T19:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325879#M97146</link>
      <description>&lt;P&gt;Hmmm.  Okay, @ellliotproebstel tag me sometime this weekend if it hasn't gotten done, and I'll rattle some cages.  I thought that was mostly automatic. &lt;/P&gt;

&lt;P&gt;@lfedak, any idea who needs to be pinged to allow this extremely helpful person into the slack fold?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:47:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325879#M97146</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-12-08T19:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325880#M97147</link>
      <description>&lt;P&gt;"Dalsplaining" -- that is great.&lt;BR /&gt;
@elliotproebstel, we love your participation on Answers! On it and will update if there's any roadblack to approval for Slack.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325880#M97147</guid>
      <dc:creator>lfedak_splunk</dc:creator>
      <dc:date>2017-12-08T19:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325881#M97148</link>
      <description>&lt;P&gt;^^ See comment above&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325881#M97148</guid>
      <dc:creator>lfedak_splunk</dc:creator>
      <dc:date>2017-12-08T19:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325882#M97149</link>
      <description>&lt;P&gt;Thanks, @lfedak. I appreciate it!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 19:53:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325882#M97149</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-08T19:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325883#M97150</link>
      <description>&lt;P&gt;Funny, I don’t remember helping much!  Happy to know even if I had a small part in creating a splunk monster like you though @daljeanis.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 23:05:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325883#M97150</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-12-08T23:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two searches and count multiple fields and values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325884#M97151</link>
      <description>&lt;P&gt;Went the route of the other answer, but this makes good sense too.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 04:07:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-two-searches-and-count-multiple-fields-and-values/m-p/325884#M97151</guid>
      <dc:creator>glenngermiathen</dc:creator>
      <dc:date>2017-12-09T04:07:55Z</dc:date>
    </item>
  </channel>
</rss>

