<?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: Using fieldformat and rename in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106281#M27631</link>
    <description>&lt;P&gt;Not sure if this will answer your question but hopefully it will point some of us in the right direction. Many thanks to superstar Splunker Cindy McCririe!&lt;/P&gt;

&lt;P&gt;My situation was similar but not identical which is why I'm not sure I will answer the original question.&lt;/P&gt;

&lt;P&gt;renaming would fail with the same empty column, as would &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fieldformat "Expected Value" = "$" + tostring("Expected Value","Commas")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but THIS works. . .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Expected Value" = round(Number * (Probability/100))
| fieldformat "Expected Value" = "$" + tostring('Expected Value',"Commas")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;(Note the single quotes instead of double quotes in the fieldformat command)&lt;/EM&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table Number, Probability, "Expected Value"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jul 2013 18:36:50 GMT</pubDate>
    <dc:creator>gwallin042</dc:creator>
    <dc:date>2013-07-25T18:36:50Z</dc:date>
    <item>
      <title>Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106276#M27626</link>
      <description>&lt;P&gt;Hey there,&lt;/P&gt;
&lt;P&gt;I'm trying to do two things and it looks like I can't. I have some fields with ugly names like "Current_SuccessPercent" that I want to rename. I also want to format the data in the field to be human readable. So I have the following search:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;index=summary_foo
| stats sum(response_time) as response_time, sum(http_200) as http_200, sum(http_400) as http_400 by sourcetype
| eval Current_SuccessPercent = (http_200 / (http_200 + http_400)) * 100
| fieldformat "Response Time" = tostring(round(response_time,2),"commas")." ms"
| fieldformat "Success Ratio" = tostring(round(Current_SuccessPercent,0))."%"
| rename sourcetype as Sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In my results table this gives me two columns, &lt;EM&gt;Current_SuccessPercent&lt;/EM&gt; and &lt;EM&gt;Success Ratio&lt;/EM&gt;. The output is formatted correctly on &lt;EM&gt;Success Ratio&lt;/EM&gt; but the sorting does not work correctly. And the formatting is incorrect on &lt;EM&gt;Current_SuccessPercent&lt;/EM&gt; but I can sort by the values. If I use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;| fieldformat Current_SuccessPercent = tostring(round(Current_SuccessPercent,0))."%"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The formatting is correct and I can sort appropriately. But then the column name looks bad and if I try to rename it I break formatting (I see two columns, one with my unformatted data, and one that is empty with the correct column name). Or if I try to rename before the fieldformat I cannot reference a column name with spaces in it inside the round method.&lt;/P&gt;
&lt;P&gt;So can I not rename a column AND use fieldformatting AND be able to sort by that column?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 18:07:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106276#M27626</guid>
      <dc:creator>tyleraball</dc:creator>
      <dc:date>2020-06-08T18:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106277#M27627</link>
      <description>&lt;P&gt;have you tried changing fieldformat to eval ?&lt;/P&gt;

&lt;P&gt;I did that and was able to sort&lt;/P&gt;

&lt;P&gt;also, Success Ratio (in my tests) came out to 1% for a 100% success, I ended up multiplying by 100 in the eval Current_SuccessPercent line to get a 100%&lt;/P&gt;

&lt;P&gt;--&lt;BR /&gt;
Jeremy&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2012 22:41:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106277#M27627</guid>
      <dc:creator>jguarini</dc:creator>
      <dc:date>2012-10-29T22:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106278#M27628</link>
      <description>&lt;P&gt;Using eval leaves it as a string so that "973 ms" appears before "9" - that breaks my ascending sort.  I have also updated my example with your suggestion about the success ratio - I was doing that in my actual query but forgot to pull it into this simple example.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2012 23:07:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106278#M27628</guid>
      <dc:creator>tyleraball</dc:creator>
      <dc:date>2012-10-29T23:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106279#M27629</link>
      <description>&lt;P&gt;Just wondering if this ever got solved? &lt;/P&gt;

&lt;P&gt;Still appears to be an issue in 5.0.2.&lt;/P&gt;

&lt;P&gt;I am having a similar issue where I lose the fieldformat if I do a rename and it has spaces in the field.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2013 00:29:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106279#M27629</guid>
      <dc:creator>Lucas_K</dc:creator>
      <dc:date>2013-04-17T00:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106280#M27630</link>
      <description>&lt;P&gt;I'm also having this issue... Splunk team, are you out there?&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2013 02:27:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106280#M27630</guid>
      <dc:creator>dennywebb</dc:creator>
      <dc:date>2013-05-13T02:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106281#M27631</link>
      <description>&lt;P&gt;Not sure if this will answer your question but hopefully it will point some of us in the right direction. Many thanks to superstar Splunker Cindy McCririe!&lt;/P&gt;

&lt;P&gt;My situation was similar but not identical which is why I'm not sure I will answer the original question.&lt;/P&gt;

&lt;P&gt;renaming would fail with the same empty column, as would &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fieldformat "Expected Value" = "$" + tostring("Expected Value","Commas")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but THIS works. . .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Expected Value" = round(Number * (Probability/100))
| fieldformat "Expected Value" = "$" + tostring('Expected Value',"Commas")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;(Note the single quotes instead of double quotes in the fieldformat command)&lt;/EM&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table Number, Probability, "Expected Value"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 18:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106281#M27631</guid>
      <dc:creator>gwallin042</dc:creator>
      <dc:date>2013-07-25T18:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106282#M27632</link>
      <description>&lt;P&gt;Same issue. Is there a solution?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2014 08:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106282#M27632</guid>
      <dc:creator>MegSplunk</dc:creator>
      <dc:date>2014-01-17T08:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106283#M27633</link>
      <description>&lt;P&gt;If I do the above and try to use the chart command, it fails. Charts are blank. Any workaround for this?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2014 08:48:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106283#M27633</guid>
      <dc:creator>MegSplunk</dc:creator>
      <dc:date>2014-01-17T08:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106284#M27634</link>
      <description>&lt;P&gt;same issue, still i dont think there is a solution for it?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 11:26:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106284#M27634</guid>
      <dc:creator>ashish9433</dc:creator>
      <dc:date>2016-09-13T11:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using fieldformat and rename</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106285#M27635</link>
      <description>&lt;P&gt;Way late to this answer but hopefully it will help future searchers. Splunk seems to use hoisting with the rename command. Hoisting is when a variable or expression is hoisted to the top of the current scope and evaluated before anything else. When I was using the rename command it was at the end of my table after my fieldformat commands and resulted in incorrect output. Once I switched the variable names in my fieldformat commands to the renamed variables, my output was correct. ,Way late to this answer but hopefully it will help future searchers. &lt;BR /&gt;
I used the table command  with fieldformat to parse my data. I had my rename command after my fieldformat which then resulted in incorrect results. I believe that rename is hoisted similar to how javascript hoists variables to the beginning of their scope before evaluating them. So when I used rename, it was hoisted to the top of the table scope, my variables were renamed and then had fieldformat run on them resulting in incorrect results. Once you use rename you need to use the renamed variables in your fieldformat functions for the data to process properly. &lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 13:49:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-fieldformat-and-rename/m-p/106285#M27635</guid>
      <dc:creator>nberens</dc:creator>
      <dc:date>2020-06-02T13:49:57Z</dc:date>
    </item>
  </channel>
</rss>

