<?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 do you re-arrange columns from a &amp;quot;stats count&amp;quot; function? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169089#M48289</link>
    <description>&lt;P&gt;The first line builds an example event. The second like is from your query. The third line is my solution, use &lt;CODE&gt;table&lt;/CODE&gt; to reorder columns.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Oct 2014 20:34:26 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-10-16T20:34:26Z</dc:date>
    <item>
      <title>How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169086#M48286</link>
      <description>&lt;P&gt;My existing query produces a table that has the following columns in this order:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Source IP&lt;/LI&gt;
&lt;LI&gt;Count&lt;/LI&gt;
&lt;LI&gt;Destination IP&lt;/LI&gt;
&lt;LI&gt;Destination Port&lt;/LI&gt;
&lt;LI&gt;Unique URLs&lt;/LI&gt;
&lt;LI&gt;URLs&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I'd like to rearrange the table so that it is:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Count&lt;/LI&gt;
&lt;LI&gt;Source IP&lt;/LI&gt;
&lt;LI&gt;Destination IP&lt;/LI&gt;
&lt;LI&gt;Destination Port&lt;/LI&gt;
&lt;LI&gt;Unique URLs&lt;/LI&gt;
&lt;LI&gt;URLs&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The trouble I'm having is that I can't find any documentation about how to use "stats count &lt;STRONG&gt;______&lt;/STRONG&gt;".  I've found &lt;CODE&gt;stats count by&lt;/CODE&gt; and &lt;CODE&gt;stats count as&lt;/CODE&gt; but having trouble using them to how I would like and not finding any explanation on how to best use them, or why you would use one over the other.&lt;/P&gt;

&lt;P&gt;The first column that I want is the total count, so how do I say "stats count by count?"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Existing query:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=palo dst_port!=80 dst_port!=443 method=POST | regex url="^(\d{1,3}\.){3}\d{1,3}.+" | stats count AS "Total Hits", values(dst_ip), values(dst_port), dc(url), values(url) by src_ip | sort -"Total Hits"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;EDIT: Solution:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=palo dst_port!=80 dst_port!=443 method=POST | regex url="^(\d{1,3}\.){3}\d{1,3}.+" | stats count AS "Total Hits", values(dst_ip) AS "Dest. IP's", values(dst_port) AS "Dest. Port", dc(url) AS "Unique URLs", values(url) AS "URLs" by src_ip | rename src_ip AS "Source IP" | table "Total Hits", "Source IP", "Dest. IP's", "Dest. Port", "Unique URLs", "URLs", | sort -"Total Hits"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:13:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169086#M48286</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2014-10-16T20:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169087#M48287</link>
      <description>&lt;P&gt;You can use &lt;CODE&gt;table&lt;/CODE&gt; to reorder columns:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval dst_ip = "foo" | eval dst_port = "bar" | eval url = "baz" | eval src_ip = "whee"
| stats count AS "Total Hits", values(dst_ip), values(dst_port), dc(url), values(url) by src_ip
| table "Total Hits" src_ip values(dst_ip) values(dst_port) dc(url) values(url)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:16:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169087#M48287</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-16T20:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169088#M48288</link>
      <description>&lt;P&gt;Thanks for the quick response.  Would you expand on a few things?  I'm confused why you run stats count by itself, then do a bunch of evals, then do stats count again?  I wasn't sure if you were just building an example or if this was required syntax.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:27:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169088#M48288</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2014-10-16T20:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169089#M48289</link>
      <description>&lt;P&gt;The first line builds an example event. The second like is from your query. The third line is my solution, use &lt;CODE&gt;table&lt;/CODE&gt; to reorder columns.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:34:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169089#M48289</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-16T20:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169090#M48290</link>
      <description>&lt;P&gt;Ok, now I understand!  Thanks for the clarification.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:35:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169090#M48290</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2014-10-16T20:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do you re-arrange columns from a "stats count" function?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169091#M48291</link>
      <description>&lt;P&gt;&lt;IMG src="http://pic.armedcats.net/n/na/narf/2014/10/16/TheMoreYouKnow.gif" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2014 20:48:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-re-arrange-columns-from-a-quot-stats-count-quot/m-p/169091#M48291</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-16T20:48:35Z</dc:date>
    </item>
  </channel>
</rss>

