<?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 Rename a Column When Using Stats Function in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300692#M175022</link>
    <description>&lt;P&gt;Good morning,&lt;/P&gt;

&lt;P&gt;This must be really simple.  I have the query:&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" by user|sort -Count&lt;/P&gt;

&lt;P&gt;I want to rename the user column to "User".  I'm particular and like my words/heading capitalized.  I've tried:&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" values(user) as User by User|sort -Count&lt;/P&gt;

&lt;P&gt;I get the following error:&lt;/P&gt;

&lt;P&gt;Error in 'stats' command: The output field 'User' cannot have the same name as a group-by field.&lt;/P&gt;

&lt;P&gt;I've tried some other things as well and no luck.  The closest I got was &lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" values(user) as User by user|sort -Count&lt;/P&gt;

&lt;P&gt;and that created two columns with the same data (user and User).  I suppose I could delete the "user" column from the final output.  Any suggestions?  Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Apr 2017 15:27:53 GMT</pubDate>
    <dc:creator>SplunkLunk</dc:creator>
    <dc:date>2017-04-03T15:27:53Z</dc:date>
    <item>
      <title>Rename a Column When Using Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300692#M175022</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;

&lt;P&gt;This must be really simple.  I have the query:&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" by user|sort -Count&lt;/P&gt;

&lt;P&gt;I want to rename the user column to "User".  I'm particular and like my words/heading capitalized.  I've tried:&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" values(user) as User by User|sort -Count&lt;/P&gt;

&lt;P&gt;I get the following error:&lt;/P&gt;

&lt;P&gt;Error in 'stats' command: The output field 'User' cannot have the same name as a group-by field.&lt;/P&gt;

&lt;P&gt;I've tried some other things as well and no luck.  The closest I got was &lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" values(user) as User by user|sort -Count&lt;/P&gt;

&lt;P&gt;and that created two columns with the same data (user and User).  I suppose I could delete the "user" column from the final output.  Any suggestions?  Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300692#M175022</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2017-04-03T15:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a Column When Using Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300693#M175023</link>
      <description>&lt;P&gt;try this one..&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype=[my sourcetype] event=login_fail|stats count as Count values(event) as Event values(ip) as "IP Address" by user|sort -Count|rename user as User&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:31:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300693#M175023</guid>
      <dc:creator>kiran331</dc:creator>
      <dc:date>2017-04-03T15:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a Column When Using Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300694#M175024</link>
      <description>&lt;P&gt;I'm surprised that splunk let you do that last one.  At one point the search manual says you CANT use a &lt;CODE&gt;group by&lt;/CODE&gt; field as one of the &lt;CODE&gt;stats&lt;/CODE&gt; fields, and gives an example of creating a second field with &lt;CODE&gt;eval&lt;/CODE&gt; in order to make that work.  &lt;/P&gt;

&lt;P&gt;KIran331's answer is correct, just use the rename command after the stats command runs.  (... Or before, that works as well.)&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:37:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300694#M175024</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-03T15:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a Column When Using Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300695#M175025</link>
      <description>&lt;P&gt;You can pipe a table after your stats and then rename your table fields:&lt;BR /&gt;
    base_search | stats count by field1,field2| table field1 field2 count | rename field1 as NewFieldName1&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300695#M175025</guid>
      <dc:creator>gehinger</dc:creator>
      <dc:date>2017-04-03T15:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a Column When Using Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300696#M175026</link>
      <description>&lt;P&gt;Thanks.  I figured I'd be able to do it within the stats function.  I should have tried rename after sort.  Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:47:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rename-a-Column-When-Using-Stats-Function/m-p/300696#M175026</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2017-04-03T15:47:11Z</dc:date>
    </item>
  </channel>
</rss>

