<?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 Combining stats search results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159379#M44971</link>
    <description>&lt;P&gt;I run a search on a field that has multiple values.  For example the field quest_name has the following values&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com&lt;BR /&gt;
2   wpad.tascnet.tasc.com&lt;BR /&gt;
3   wpad.stafford.net&lt;/P&gt;

&lt;P&gt;1). I can compute the number of records that exists for each field value with the following search&lt;/P&gt;

&lt;P&gt;index=dns* quest_name=wpad* | stats count by quest_name  | sort - count&lt;/P&gt;

&lt;P&gt;The results are&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name      count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com   5777&lt;BR /&gt;
2   wpad.tascnet.tasc.com   1324&lt;BR /&gt;
3   wpad.stafford.net   225&lt;/P&gt;

&lt;P&gt;2). I can compute the total number of records for all values for quest_name with the following search&lt;/P&gt;

&lt;P&gt;index=dns* quest_name=wpad* | stats count(quest_name) AS total&lt;/P&gt;

&lt;P&gt;The results are&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   9492&lt;/P&gt;

&lt;P&gt;3). Now I want to obtain the percentage of each field value in relation to the "total" value using a single search to show the following calculations:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name      count   percent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com   5777    5777/9492=&lt;BR /&gt;
2   wpad.tascnet.tasc.com   1324    1324/9492=&lt;BR /&gt;
3   wpad.stafford.net   225 225/9492= &lt;/P&gt;

&lt;P&gt;This I have not been able to do.  Your help is requested.  Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:34:37 GMT</pubDate>
    <dc:creator>Thuan</dc:creator>
    <dc:date>2020-09-28T16:34:37Z</dc:date>
    <item>
      <title>Combining stats search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159379#M44971</link>
      <description>&lt;P&gt;I run a search on a field that has multiple values.  For example the field quest_name has the following values&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com&lt;BR /&gt;
2   wpad.tascnet.tasc.com&lt;BR /&gt;
3   wpad.stafford.net&lt;/P&gt;

&lt;P&gt;1). I can compute the number of records that exists for each field value with the following search&lt;/P&gt;

&lt;P&gt;index=dns* quest_name=wpad* | stats count by quest_name  | sort - count&lt;/P&gt;

&lt;P&gt;The results are&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name      count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com   5777&lt;BR /&gt;
2   wpad.tascnet.tasc.com   1324&lt;BR /&gt;
3   wpad.stafford.net   225&lt;/P&gt;

&lt;P&gt;2). I can compute the total number of records for all values for quest_name with the following search&lt;/P&gt;

&lt;P&gt;index=dns* quest_name=wpad* | stats count(quest_name) AS total&lt;/P&gt;

&lt;P&gt;The results are&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   9492&lt;/P&gt;

&lt;P&gt;3). Now I want to obtain the percentage of each field value in relation to the "total" value using a single search to show the following calculations:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;quest_name      count   percent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;1   wpad.TASCNET.tasc.com   5777    5777/9492=&lt;BR /&gt;
2   wpad.tascnet.tasc.com   1324    1324/9492=&lt;BR /&gt;
3   wpad.stafford.net   225 225/9492= &lt;/P&gt;

&lt;P&gt;This I have not been able to do.  Your help is requested.  Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:34:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159379#M44971</guid>
      <dc:creator>Thuan</dc:creator>
      <dc:date>2020-09-28T16:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Combining stats search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159380#M44972</link>
      <description>&lt;P&gt;Hello Thuan,&lt;BR /&gt;
Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dns quest_name=wpad | stats count by quest_name|eval a="a1"|join a[|search index=dns quest_name=wpad | stats count(quest_name) AS total|eval a="a1"|table a,total]|eval percent=(count/total)*100|eval percentage=percent.%|table quest_name,count,percentage
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR you may as look at the below simple one, i guess both give the same result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dns quest_name=wpad*|top quest_name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 20:04:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159380#M44972</guid>
      <dc:creator>linu1988</dc:creator>
      <dc:date>2014-05-09T20:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combining stats search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159381#M44973</link>
      <description>&lt;P&gt;The top command can definitely give you the result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=dns quest_name=wpad* | top limit=0 quest_name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Other option is as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dns quest_name=wpad | stats count by quest_name | sort - count | eventstats sum(count) as total | eval percent=round(count*100/total,2) | fields - total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 May 2014 20:07:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159381#M44973</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-05-12T20:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Combining stats search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159382#M44974</link>
      <description>&lt;P&gt;Thank you for the diversity of answers.&lt;BR /&gt;
I now get to know how to use subsearch, join, eventstats.&lt;BR /&gt;
One note though about the captchas.  I have tried to answer much earlier but I have so many captchas.&lt;/P&gt;</description>
      <pubDate>Tue, 13 May 2014 16:01:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-stats-search-results/m-p/159382#M44974</guid>
      <dc:creator>Thuan</dc:creator>
      <dc:date>2014-05-13T16:01:54Z</dc:date>
    </item>
  </channel>
</rss>

