<?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: stats list() command will not display items after fieldformat. How can I resolve it? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191157#M55011</link>
    <description>&lt;P&gt;What you want to do is apply the formatting after you do the the stats command. You should get your average calculated based on the numbers and then convert it to a string.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2015 16:34:55 GMT</pubDate>
    <dc:creator>aholzer</dc:creator>
    <dc:date>2015-01-23T16:34:55Z</dc:date>
    <item>
      <title>stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191154#M55008</link>
      <description>&lt;P&gt;This a fairly big query, so only run it for the past couple of weeks.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source=*license_usage.log type="Usage"|bin _time span=1d
|eval h=lower(h)
| stats sum(b) as b by idx, h, st, _time | stats avg(b) as dailyAverage, max(b) as dailyMax by idx, h,
 st
|appendpipe [stats sum(dailyAverage) as dailyAverage sum(dailyMax) as dailyMax by idx,h | eval st="--TOTAL  IN MB BY HOST--"]
|appendpipe [stats sum(dailyAverage) as dailyAverage sum(dailyMax) as dailyMax by idx | eval st="##-TOTAL  IN MB BY APPLICATION-##"]
|eval dailyAverage=round(dailyAverage/1024/1024,3)
|eval dailyMax=round(dailyMax/1024/1024,3)
| sort idx, h,dailyAverage
|stats  list(h) as h, list(st) as Sourcetype,list(dailyAverage) as "dailyAverage", list(dailyMax) as dailyMax by idx
|rename h as "Server Name", st as "Data Source", dailyAverage as "Daily Data Average in MB", dailyMax as "Maximum Daily Data"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The issue is that I want my fields showing size in MB to have comma separation for readability. We usually obtain that through a search query like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|fieldformat dailyAverage= tostring(dailyAverage,"commas")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This query line works until I run a stats command and try to list the values. I end up with a blank dailyAverage column and the corresponding size column continues to show numerical values with no commas. Somehow the list() function is negating the fieldformat command.&lt;/P&gt;

&lt;P&gt;Any help appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 15:27:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191154#M55008</guid>
      <dc:creator>feickertmd</dc:creator>
      <dc:date>2015-01-23T15:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191155#M55009</link>
      <description>&lt;P&gt;Are you doing the formatting before or after the stats?&lt;/P&gt;

&lt;P&gt;If you do it before, then it's like converting all your numbers to strings, and trying to calculate the average of a string.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:27:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191155#M55009</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-01-23T16:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191156#M55010</link>
      <description>&lt;P&gt;I have attempted it right before and after line 10. If I add it before line 10 and delete everything after, I get the rendering I want. But when I then apply list(), it dies.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:30:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191156#M55010</guid>
      <dc:creator>feickertmd</dc:creator>
      <dc:date>2015-01-23T16:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191157#M55011</link>
      <description>&lt;P&gt;What you want to do is apply the formatting after you do the the stats command. You should get your average calculated based on the numbers and then convert it to a string.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:34:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191157#M55011</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-01-23T16:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191158#M55012</link>
      <description>&lt;P&gt;Tried it, by adding the fieldformat after stats but before rename.&lt;/P&gt;

&lt;P&gt;I supplied the code, it's an internal index, so try it yourself.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:37:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191158#M55012</guid>
      <dc:creator>feickertmd</dc:creator>
      <dc:date>2015-01-23T16:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191159#M55013</link>
      <description>&lt;P&gt;Got it. The reason for that is because you have created a multi-value field (mvfield) by using list(), and the fieldformatter doesn't know how to handle those.&lt;/P&gt;

&lt;P&gt;You are either going to have to figure out how to manipulate mvfields to iterate through all the values in the mvfield, or you are going to have to calculate the daily average in a step before you use the stats list, so that you can convert it to a formatted string and then put it in the stats list().&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:44:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191159#M55013</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2015-01-23T16:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191160#M55014</link>
      <description>&lt;P&gt;Tried that as well. If you add fieldformat before line 10, it applies to single value fields and works great. But then if you try to aggregate them in list after fieldformat... boom.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 16:46:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191160#M55014</guid>
      <dc:creator>feickertmd</dc:creator>
      <dc:date>2015-01-23T16:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191161#M55015</link>
      <description>&lt;P&gt;The problem arises because of how fieldformat works. It creates a "string version" of the field as well as the original (numeric) version. Most likely the stats command is unclear about which version of the field should be used - or something like that. Try this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=_internal source=*license_usage.log type="Usage" 
 | bin _time span=1d | eval h=lower(h)
 | stats sum(b) as b by idx h st _time 
 | stats avg(b) as dailyAverage, max(b) as dailyMax by idx, h, st
 |appendpipe [stats sum(dailyAverage) as dailyAverage sum(dailyMax) as dailyMax by idx h 
              | eval st="--TOTAL  IN MB BY HOST--"]
 |appendpipe [stats sum(dailyAverage) as dailyAverage sum(dailyMax) as dailyMax by idx 
              | eval st="##-TOTAL  IN MB BY APPLICATION-##"]
 |eval dailyAverage=tostring(round(dailyAverage/1024/1024,3),"commas")
 |eval dailyMax=round(dailyMax/1024/1024,3)
 | sort idx h dailyAverage
 | stats  list(h) as h list(st) as Sourcetype list(dailyAverage) as dailyAverage list(dailyMax) as dailyMax by idx
 | rename h as "Server Name" st as "Data Source" dailyAverage as "Daily Data Average in MB"
          dailyMax as "Maximum Daily Data"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can't actually test this completely, but I think it should work.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 01:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191161#M55015</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-01-26T01:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: stats list() command will not display items after fieldformat. How can I resolve it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191162#M55016</link>
      <description>&lt;P&gt;That's what I needed, was eval vs. fieldformat. Thanks, lgiunn!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 14:51:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-list-command-will-not-display-items-after-fieldformat-How/m-p/191162#M55016</guid>
      <dc:creator>feickertmd</dc:creator>
      <dc:date>2015-01-26T14:51:27Z</dc:date>
    </item>
  </channel>
</rss>

