<?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 get the sum of count on specific field name? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141097#M39045</link>
    <description>&lt;P&gt;The search is a little strange, in that the second stats command will &lt;EM&gt;effectively&lt;/EM&gt; be the same as &lt;CODE&gt;| rename count as "list(count)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;To explain why, coming out of the first stats command,  stats will guarantee that each row is a unique combination of SourceIP_city and SourceIP_country.  Therefore for each combination of those two fields there will only be one count.  Therefore when the second stats comes along and says "list all the counts for every combination", there will be exactly one.  In other words normally list(foo) would give you a multivalued-field but in this case it never will.  Each row will have only a single value for the count.&lt;/P&gt;

&lt;P&gt;So... remove that second redundant stats clause. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_city, SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and to get a rollup of the whole thing by just SourceIP_country_name,   the easiest way is to run: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if for some reason you want to leave the stats command as it is in your base search,  you could also just tack on &lt;CODE&gt;| stats sum(count) as count by SourceIP_country_name  | sort by -count&lt;/CODE&gt;, giving a full expression of: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_city, SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| stats sum(count) as count by SourceIP_country_name  | sort by -count&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 18:53:12 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2020-09-28T18:53:12Z</dc:date>
    <item>
      <title>How to get the sum of count on specific field name?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141096#M39044</link>
      <description>&lt;P&gt;I have the following search query:&lt;/P&gt;

&lt;P&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_city, SourceIP_country_name  | stats list(count) by SourceIP_city, SourceIP_country_name | sort by -list(count)&lt;/P&gt;

&lt;P&gt;that produces:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/28625-capture.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;How can I add/sum the SourceIP_country_name field to produce the following results:&lt;/P&gt;

&lt;P&gt;Row Labels       Sum of Count&lt;BR /&gt;
United States        125703&lt;BR /&gt;
China                100991&lt;BR /&gt;
Ukraine              21944&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:56:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141096#M39044</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-09-28T18:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum of count on specific field name?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141097#M39045</link>
      <description>&lt;P&gt;The search is a little strange, in that the second stats command will &lt;EM&gt;effectively&lt;/EM&gt; be the same as &lt;CODE&gt;| rename count as "list(count)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;To explain why, coming out of the first stats command,  stats will guarantee that each row is a unique combination of SourceIP_city and SourceIP_country.  Therefore for each combination of those two fields there will only be one count.  Therefore when the second stats comes along and says "list all the counts for every combination", there will be exactly one.  In other words normally list(foo) would give you a multivalued-field but in this case it never will.  Each row will have only a single value for the count.&lt;/P&gt;

&lt;P&gt;So... remove that second redundant stats clause. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_city, SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and to get a rollup of the whole thing by just SourceIP_country_name,   the easiest way is to run: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if for some reason you want to leave the stats command as it is in your base search,  you could also just tack on &lt;CODE&gt;| stats sum(count) as count by SourceIP_country_name  | sort by -count&lt;/CODE&gt;, giving a full expression of: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" ImmediateAction=Block | geoip SourceIP | stats count by SourceIP_city, SourceIP_country_name | sort by -count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| stats sum(count) as count by SourceIP_country_name  | sort by -count&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:53:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141097#M39045</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-28T18:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum of count on specific field name?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141098#M39046</link>
      <description>&lt;P&gt;Sorry for the delay in replying. Thx for the information, and the clarification on the search. How would I modify the search to show the Source_IP_country_name and then each SourceIP_city with its corresponding count? So we'd have:&lt;/P&gt;

&lt;P&gt;CountryName                  CityName              Couint &lt;BR /&gt;
USA&lt;BR /&gt;&lt;BR /&gt;
                                           Kansas City            100&lt;BR /&gt;
                                           Los Angeles              77&lt;BR /&gt;
China&lt;BR /&gt;
                                           Beijing                        45&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:58:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141098#M39046</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-09-28T18:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum of count on specific field name?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141099#M39047</link>
      <description>&lt;P&gt;Playing around I was able to sort by CountryName using the following:&lt;/P&gt;

&lt;P&gt;| stats count by SourceIP_country_name, SourceIP_city | stats list(count) by SourceIP_country_name, SourceIP_city | sort by -list(SourceIP_country_name)&lt;/P&gt;

&lt;P&gt;Is it possible to sort first by alphabetically, then numerically within the list?&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:58:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141099#M39047</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-09-28T18:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the sum of count on specific field name?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141100#M39048</link>
      <description>&lt;P&gt;Figured the sort out, as I did the following:&lt;/P&gt;

&lt;P&gt;| sort by SourceIP_country_name,-list(count)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:58:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-sum-of-count-on-specific-field-name/m-p/141100#M39048</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-09-28T18:58:33Z</dc:date>
    </item>
  </channel>
</rss>

