<?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 rounding percentage comes back blank, adding commas ruins sorting in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77329#M19541</link>
    <description>&lt;P&gt;Hi, &lt;BR /&gt;
I am using a query that uses the awesome percentage value feature built into stats. It outputs into a table that my coworkers get in a report. They love the report but they hate the formatting. This has lead me to two issues:&lt;/P&gt;

&lt;P&gt;1)  I have managed to figure out how to round most of the values into easily readable formats, but when I try and round the percentage outputs using feildformat they come back blank. Below is an example where I have tried a feildformat on 99% but not on 95%. 99% disappears There is no need for that decimal point at all, how can i get rid of it while keeping the output? Note: the values are for a duration and are indeed all numerical. &lt;/P&gt;

&lt;P&gt;95%Ms    99%Ms   &lt;/P&gt;

&lt;P&gt;2000.0000   &lt;/P&gt;

&lt;P&gt;2) Looking at the same example above my coworkers really want commas in the larger numbers, when i run this query for anything more than a few hours the total cost is in the billions. So i tried using the tostring(bytes, "commas") strategy to break up the numbers, but this ruins the table because I am no longer able to sort by total cost. Splunk seems to only want to account for the values before the first comma so 600,000 will be sorted right below 601,987,543,123.&lt;/P&gt;

&lt;P&gt;Here is the search i use: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype="Event" 
| stats min(xtime) as Min, avg(xtime) as AvgDuration, median(xtime) as Median, p95(xtime) as 95%Ms, 
          p99(xtime) as 99%Ms, max(xtime) as Max, count(xmethod) as NumCalls , sum(xtime) as TotalCost 
          by xmethod 
| eval TotalCost = (NumCalls * AvgDuration) 
| fieldformat Min=round(Min) 
| fieldformat AvgDuration=round(AvgDuration) 
| fieldformat 99%Ms=round(99%Ms) 
| fieldformat Median=round(Median) 
| fieldformat Max=round(Max) 
| fieldformat TotalCost=round(TotalCost) 
| sort -TotalCost | head 20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you so much for all your help doing my job for me!&lt;/P&gt;

&lt;P&gt;Splunk is the best!&lt;/P&gt;</description>
    <pubDate>Thu, 03 Jan 2013 18:42:16 GMT</pubDate>
    <dc:creator>jericksonpf</dc:creator>
    <dc:date>2013-01-03T18:42:16Z</dc:date>
    <item>
      <title>rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77329#M19541</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
I am using a query that uses the awesome percentage value feature built into stats. It outputs into a table that my coworkers get in a report. They love the report but they hate the formatting. This has lead me to two issues:&lt;/P&gt;

&lt;P&gt;1)  I have managed to figure out how to round most of the values into easily readable formats, but when I try and round the percentage outputs using feildformat they come back blank. Below is an example where I have tried a feildformat on 99% but not on 95%. 99% disappears There is no need for that decimal point at all, how can i get rid of it while keeping the output? Note: the values are for a duration and are indeed all numerical. &lt;/P&gt;

&lt;P&gt;95%Ms    99%Ms   &lt;/P&gt;

&lt;P&gt;2000.0000   &lt;/P&gt;

&lt;P&gt;2) Looking at the same example above my coworkers really want commas in the larger numbers, when i run this query for anything more than a few hours the total cost is in the billions. So i tried using the tostring(bytes, "commas") strategy to break up the numbers, but this ruins the table because I am no longer able to sort by total cost. Splunk seems to only want to account for the values before the first comma so 600,000 will be sorted right below 601,987,543,123.&lt;/P&gt;

&lt;P&gt;Here is the search i use: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype="Event" 
| stats min(xtime) as Min, avg(xtime) as AvgDuration, median(xtime) as Median, p95(xtime) as 95%Ms, 
          p99(xtime) as 99%Ms, max(xtime) as Max, count(xmethod) as NumCalls , sum(xtime) as TotalCost 
          by xmethod 
| eval TotalCost = (NumCalls * AvgDuration) 
| fieldformat Min=round(Min) 
| fieldformat AvgDuration=round(AvgDuration) 
| fieldformat 99%Ms=round(99%Ms) 
| fieldformat Median=round(Median) 
| fieldformat Max=round(Max) 
| fieldformat TotalCost=round(TotalCost) 
| sort -TotalCost | head 20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you so much for all your help doing my job for me!&lt;/P&gt;

&lt;P&gt;Splunk is the best!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 18:42:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77329#M19541</guid>
      <dc:creator>jericksonpf</dc:creator>
      <dc:date>2013-01-03T18:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77330#M19542</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype="Event" 
| stats min(xtime) as Min, avg(xtime) as AvgDuration, median(xtime) as Median, p95(xtime) as 95Ms, 
          p99(xtime) as 99Ms, max(xtime) as Max, count(xmethod) as NumCalls , sum(xtime) as TotalCost 
          by xmethod 
| eval TotalCost = (NumCalls * AvgDuration) 
| eval Min=round(Min) 
| eval AvgDuration=round(AvgDuration) 
| eval 99Ms=round(99Ms) 
| eval 95Ms=round(95Ms) 
| eval Median=round(Median) 
| eval Max=round(Max) 
| eval TotalCost=round(TotalCost) 
| rename 99MS as "99% Ms", 95Ms as "95% Ms"
| sort -TotalCost 
| fieldformat TotalCost = string(TotalCost,"commas")
| head 20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I did a few things differently. First, &lt;CODE&gt;eval&lt;/CODE&gt; changes both the value and the representation for a field; &lt;CODE&gt;fieldformat&lt;/CODE&gt; should change only the representation. (This doesn't seem to be &lt;EM&gt;exactly&lt;/EM&gt; true, but...) So, I used &lt;CODE&gt;eval&lt;/CODE&gt; whenever I wanted to change the actual value for the field.&lt;/P&gt;

&lt;P&gt;Second, just in case &lt;CODE&gt;fieldformat&lt;/CODE&gt; was screwing up the sort, I did the &lt;CODE&gt;sort&lt;/CODE&gt; first and then the &lt;CODE&gt;fieldformat&lt;/CODE&gt; on TotalCost. The &lt;CODE&gt;fieldformat&lt;/CODE&gt; command really &lt;EM&gt;shouldn't&lt;/EM&gt; be screwing up the sort, though.&lt;/P&gt;

&lt;P&gt;Finally, and most important - you can't use a &lt;STRONG&gt;%&lt;/STRONG&gt; in the name of a field. It doesn't break the stats command, but it silently breaks most other commands, like &lt;CODE&gt;eval&lt;/CODE&gt; and &lt;CODE&gt;fieldformat&lt;/CODE&gt;. So I used different names, and renamed the fields to a display-friendly name just before they are output.&lt;/P&gt;

&lt;P&gt;Here is the reference to &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Createandmaintainsearch-timefieldextractionsthroughconfigurationfiles#Regular_expressions_and_field_name_syntax"&gt;Field Name Syntax&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 20:47:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77330#M19542</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-01-03T20:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77331#M19543</link>
      <description>&lt;P&gt;Interestingly the linked docs state that a field name cannot start with 0-9 or _ ?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:31:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77331#M19543</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-01-03T21:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77332#M19544</link>
      <description>&lt;P&gt;WOW thank you so much for helping me out AGAIN lguinn you just saved me several hours of productivity and frustration. you are a lifesaver and really good at this splunk stuff. &lt;/P&gt;

&lt;P&gt;So what you posted above did not exactly work for me but it got me on the right path. I ditched the percentages, but the search was coming back with an error "eval command malformed expected )" So i took out the numbers and just used all text for the fields and it worked!!!!. &lt;BR /&gt;
Secondly above you just used the string command and my version of splunk didn't like that so i used tostring after the sort as you suggested and everything is looking fantastic!!! Thanks so much!!! &lt;/P&gt;

&lt;P&gt;Here is what i ended up with:&lt;/P&gt;

&lt;P&gt;eventtype="Event" | stats min(xtime) as Min, avg(xtime) as AvgDuration, median(xtime) as Median, p95(xtime) as ninetyfive, p99(xtime) as ninetynine, max(xtime) as Max, count(xmethod) as NumCalls , sum(xtime) as TotalCost by xmethod | eval TotalCost = (NumCalls * AvgDuration) | eval Min=round(Min) | eval AvgDuration=round(AvgDuration) | eval Median=round(Median) | eval ninetyfive=round(ninetyfive) | eval ninetynine=round(ninetynine) | eval Max=round(Max) | eval TotalCost=round(TotalCost) | sort -TotalCost | fieldformat TotalCost = tostring(TotalCost,"commas") | head 20&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:32:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77332#M19544</guid>
      <dc:creator>jericksonpf</dc:creator>
      <dc:date>2013-01-03T21:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77333#M19545</link>
      <description>&lt;P&gt;jonuwz you are right letters need to go first. I have now changed my fields to p95 p99 and it works&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:37:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77333#M19545</guid>
      <dc:creator>jericksonpf</dc:creator>
      <dc:date>2013-01-03T21:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: rounding percentage comes back blank, adding commas ruins sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77334#M19546</link>
      <description>&lt;P&gt;Thanks jonuwz - I should read my own links!!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2013 01:53:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rounding-percentage-comes-back-blank-adding-commas-ruins-sorting/m-p/77334#M19546</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-01-04T01:53:04Z</dc:date>
    </item>
  </channel>
</rss>

