<?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: Round result of timechart avg() in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/646861#M223880</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223382"&gt;@mxanareckless&lt;/a&gt;&amp;nbsp;- this worked for me with timechart&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timechart eval(round(avg(memUsedGB),2)) as avgmem by host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jun 2023 19:56:16 GMT</pubDate>
    <dc:creator>siddhusaus</dc:creator>
    <dc:date>2023-06-13T19:56:16Z</dc:date>
    <item>
      <title>How to round result of timechart avg()?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539365#M152547</link>
      <description>&lt;P&gt;I cannot figure out how to round the values presented on the timechart. My SPL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=$radio_token$ host=$dropdown_token2$ sourcetype=cpu
| eval cpuavg=round(cpu_load_percent, 2)
| timechart avg(cpuavg)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And these are the results:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mxanareckless_0-1612993558619.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/12880iF86DCC9B68613AA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mxanareckless_0-1612993558619.png" alt="mxanareckless_0-1612993558619.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How can I get that to appear as 1%, instead of that huge clunky number?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 23:39:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539365#M152547</guid>
      <dc:creator>mxanareckless</dc:creator>
      <dc:date>2023-06-14T23:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539367#M152549</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223382"&gt;@mxanareckless&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Round after the timechart, not before, like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=$radio_token$ host=$dropdown_token2$ sourcetype=cpu
| timechart avg(cpu_load_percent) as cpuavg
| eval cpuavg=round(cpuavg, 2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 22:00:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539367#M152549</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-02-10T22:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539750#M152663</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&lt;/P&gt;&lt;P&gt;That worked for&amp;nbsp;&lt;STRONG&gt;| timechart avg(cpu_load_percent) as cpuavg&lt;/STRONG&gt;&lt;BR /&gt;However, if I add&amp;nbsp;&lt;STRONG&gt;by host&lt;/STRONG&gt; to the end, the rounding no longer works.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index sourcetype=vmstat
| where like(host, "kdc%")
| timechart avg(memUsedGB) as avgmem by host
| eval avgmem=round(avgmem,2)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mxanareckless_0-1613159267155.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/12926iBBF16253EE56C23B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mxanareckless_0-1613159267155.png" alt="mxanareckless_0-1613159267155.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 19:48:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539750#M152663</guid>
      <dc:creator>mxanareckless</dc:creator>
      <dc:date>2021-02-12T19:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539762#M152668</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223382"&gt;@mxanareckless&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you use a split by clause, the name of the fields generated are the names of the split and no longer the name you want to give it, so if you look at the statistics tab when you do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart avg(memUsedGB) as avgmem &lt;/LI-CODE&gt;&lt;P&gt;you will get a column called avgmem, which you can easily round.&lt;/P&gt;&lt;P&gt;When you do a split by, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart avg(memUsedGB) as avgmem by host&lt;/LI-CODE&gt;&lt;P&gt;you will see the columns do not have anything to do with avgmem in their names. In this case, you can't just use the round() function any more. You will have to use the foreach statement, which will iterate through each field, like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart avg(memUsedGB) as avgmem by host
| foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=round(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,2) ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;What this is doing is for each field name matching *, it will then run the eval statement in the subsearch and the &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; reference is the actual value of the field, so you are just rounding the fields without having to know their names.&lt;/P&gt;&lt;P&gt;foreach is a very powerful and is one of the commands you can use well if you use good naming conventions in your field names in your SPL.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Foreach" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Foreach&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope this was useful.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 22:04:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/539762#M152668</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-02-12T22:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/541065#M153167</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your insightful reply. I think I understand the concept, but when I apply your suggestion, all of the fields returned are blank instead. I need the values in the bottom screenshot to be rounded to the nearest whole integer - the excessive decimals make it very difficult to read in reports.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="spk-foreach1.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/13030iF750E6DF2A7D0418/image-size/large?v=v2&amp;amp;px=999" role="button" title="spk-foreach1.PNG" alt="spk-foreach1.PNG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="spk-foreach2.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/13031iB3E87A2A07D2396F/image-size/large?v=v2&amp;amp;px=999" role="button" title="spk-foreach2.PNG" alt="spk-foreach2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 18:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/541065#M153167</guid>
      <dc:creator>mxanareckless</dc:creator>
      <dc:date>2021-02-23T18:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/541144#M153189</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223382"&gt;@mxanareckless&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mmm, the only thing that may be an issue is your field names. Please change the foreach statement to&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') ]&lt;/LI-CODE&gt;&lt;P&gt;i.e. wrap the second &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; with single quotation marks.&amp;nbsp; When dealing with field names that contain non standard characters or start with numbers, you need to use single quotes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 09:16:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/541144#M153189</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-02-24T09:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/646861#M223880</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223382"&gt;@mxanareckless&lt;/a&gt;&amp;nbsp;- this worked for me with timechart&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timechart eval(round(avg(memUsedGB),2)) as avgmem by host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 19:56:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/646861#M223880</guid>
      <dc:creator>siddhusaus</dc:creator>
      <dc:date>2023-06-13T19:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Round result of timechart avg()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/696664#M236762</link>
      <description>&lt;P&gt;Perfect, worked for me thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 04:53:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-round-result-of-timechart-avg/m-p/696664#M236762</guid>
      <dc:creator>Splunked</dc:creator>
      <dc:date>2024-08-19T04:53:14Z</dc:date>
    </item>
  </channel>
</rss>

