<?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 Single-Field Multi-Value Count Difference by Multiple other Fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151023#M42311</link>
    <description>&lt;P&gt;I am trying to find the difference of the dns type values for each domain in each time bucket.  Let's say there are 10 queries and 22 responses for a given domain.  The answer would be 22-10=12.  My current search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=dns | bucket _time span=10m | rex "(?i)^.+\\s{2}\\..*?(?P&amp;lt;domain_root&amp;gt;[^\\.]+\\.[^\\.]+)(?=.$)" | stats count as c by domain_root _time dns_type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This produces the number of queries and replies per domain, but I don't know how to subtract them.  I came across what may be a different approach using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count AS c0 count(eval(dns_type="Q")) AS cq count(eval(dns_type="R")) AS cr by domain_root _time | eval d=cq-cr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this second approach is viable then would it be followed up with eval d=cq-cr even though cr and cq are for each domain and time bucket or is there another solution?  Even if the count-eval method has a solution, I am still interested in understanding how the calculations are done when the "by" term is invoked and I am interested in knowing if a solution exists for the first method (above) using "count by domain_root time dns_type"&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:31:35 GMT</pubDate>
    <dc:creator>landen99</dc:creator>
    <dc:date>2020-09-28T16:31:35Z</dc:date>
    <item>
      <title>Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151023#M42311</link>
      <description>&lt;P&gt;I am trying to find the difference of the dns type values for each domain in each time bucket.  Let's say there are 10 queries and 22 responses for a given domain.  The answer would be 22-10=12.  My current search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=dns | bucket _time span=10m | rex "(?i)^.+\\s{2}\\..*?(?P&amp;lt;domain_root&amp;gt;[^\\.]+\\.[^\\.]+)(?=.$)" | stats count as c by domain_root _time dns_type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This produces the number of queries and replies per domain, but I don't know how to subtract them.  I came across what may be a different approach using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count AS c0 count(eval(dns_type="Q")) AS cq count(eval(dns_type="R")) AS cr by domain_root _time | eval d=cq-cr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this second approach is viable then would it be followed up with eval d=cq-cr even though cr and cq are for each domain and time bucket or is there another solution?  Even if the count-eval method has a solution, I am still interested in understanding how the calculations are done when the "by" term is invoked and I am interested in knowing if a solution exists for the first method (above) using "count by domain_root time dns_type"&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:31:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151023#M42311</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2020-09-28T16:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151024#M42312</link>
      <description>&lt;P&gt;The second &lt;CODE&gt;stats&lt;/CODE&gt; seems reasonable to me. The issue with the first one is that &lt;CODE&gt;eval&lt;/CODE&gt; works on a per-event / per-row basis, so you'd have to merge each pair first before doing the calculation - the second &lt;CODE&gt;stats&lt;/CODE&gt; already does that for you.&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 20:50:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151024#M42312</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-02T20:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151025#M42313</link>
      <description>&lt;P&gt;If I did the second stats approach, how would the eval look?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count AS c0 count(eval(dns_type="Q")) AS cq count(eval(dns_type="R")) AS cr by domain_root _time | eval d=cq-cr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If so, then would this "d" be per domain and time bucket?&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 21:09:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151025#M42313</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-05-02T21:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151026#M42314</link>
      <description>&lt;P&gt;Yup, per row / per &lt;CODE&gt;domain_root&lt;/CODE&gt; and &lt;CODE&gt;_time&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 21:53:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151026#M42314</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-02T21:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151027#M42315</link>
      <description>&lt;P&gt;So&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats func(a) AS b by x y z | eval s=sum(b)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in effect creates the variable b.x.y.z so that eval "s=sum(b)"is really in effect "s=sum(b.x.y.z)" which sums for each unique combination of x, y, and z so that "table s x y z" can show a different value of "s" for each x, y, and z combination.  Is this correct?&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2014 13:09:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151027#M42315</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-05-05T13:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151028#M42316</link>
      <description>&lt;P&gt;That &lt;CODE&gt;eval&lt;/CODE&gt; isn't going to run.&lt;/P&gt;

&lt;P&gt;As for that &lt;CODE&gt;stats&lt;/CODE&gt;, it will create a table with four columns: &lt;CODE&gt;x   y   z   b&lt;/CODE&gt;&lt;BR /&gt;
You'll get one row for every combination of x, y, and z, and b will be &lt;CODE&gt;func(a)&lt;/CODE&gt; for events matching that combination.&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2014 14:48:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151028#M42316</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-05T14:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151029#M42317</link>
      <description>&lt;P&gt;You are correct.  The "sum" function requires the stat function.  I was thinking about something more like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats func(a) AS b by x y z | eval c=a+b
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 May 2014 19:49:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151029#M42317</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-05-05T19:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151030#M42318</link>
      <description>&lt;P&gt;That's going to be trouble as well, there is no field called &lt;CODE&gt;a&lt;/CODE&gt; after the &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2014 19:50:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151030#M42318</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-05T19:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151031#M42319</link>
      <description>&lt;P&gt;You are very sharp.  Let's consider eventstats, which keeps "a" then.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventstats func(a) AS b by x y z | eval c=a+b
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 May 2014 20:05:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151031#M42319</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2014-05-05T20:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Single-Field Multi-Value Count Difference by Multiple other Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151032#M42320</link>
      <description>&lt;P&gt;That'll run. Let &lt;CODE&gt;func&lt;/CODE&gt; be &lt;CODE&gt;avg&lt;/CODE&gt; for example, then this will add a field &lt;CODE&gt;c&lt;/CODE&gt; to every event that is the value of &lt;CODE&gt;a&lt;/CODE&gt; plus the average of &lt;CODE&gt;a&lt;/CODE&gt; calculated for each combination of &lt;CODE&gt;x&lt;/CODE&gt;, &lt;CODE&gt;y&lt;/CODE&gt;, and &lt;CODE&gt;z&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2014 20:08:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Single-Field-Multi-Value-Count-Difference-by-Multiple-other/m-p/151032#M42320</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-05-05T20:08:49Z</dc:date>
    </item>
  </channel>
</rss>

