<?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 How to Round in a stats command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551160#M156399</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm trying to round the average of my response_time but still getting undesirable results (all the decimal places). Can someone advise what the correct format is?&lt;/P&gt;
&lt;P&gt;stats avg(eval(round((response_time),2))) as avg_response_time&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2022 14:27:32 GMT</pubDate>
    <dc:creator>ebs</dc:creator>
    <dc:date>2022-04-08T14:27:32Z</dc:date>
    <item>
      <title>How to Round in a stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551160#M156399</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm trying to round the average of my response_time but still getting undesirable results (all the decimal places). Can someone advise what the correct format is?&lt;/P&gt;
&lt;P&gt;stats avg(eval(round((response_time),2))) as avg_response_time&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 14:27:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551160#M156399</guid>
      <dc:creator>ebs</dc:creator>
      <dc:date>2022-04-08T14:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551162#M156401</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/228215"&gt;@ebs&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats avg(eval(round(response_time,2))) as avg_response_time&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 11 May 2021 04:58:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551162#M156401</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-05-11T04:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551166#M156403</link>
      <description>&lt;P&gt;I get this error:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Error in 'eval' command: The expression is malformed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:36:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551166#M156403</guid>
      <dc:creator>ebs</dc:creator>
      <dc:date>2021-05-11T05:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551167#M156404</link>
      <description>&lt;P&gt;Do your round after the stats&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats avg(response_time) as avg_response_time
| eval avg_response_time=round(avg_response_time,2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:37:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551167#M156404</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-05-11T05:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551168#M156405</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/228215"&gt;@ebs&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal 
| eval response_time=date_hour + 0.30303
| stats avg(eval(round(response_time,2))) as avg_response_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your search ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/551168#M156405</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-05-11T05:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593105#M206441</link>
      <description>&lt;P&gt;The issue with doing it this way is you're rounding before you average it. This works if you already have values that need to be rounded and then you average that. I used values(eval(round to&amp;nbsp; round and aggregate into mv for unique values and it works well. I have not been able to find a way with stat, operation and round because it seems like eval needs to go after stats operation which defeats the purpose of a the average.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could be missing something so if anyone found a way please post as that would save me an extra line almost every time i write a dashboard.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 12:38:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593105#M206441</guid>
      <dc:creator>mal11</dc:creator>
      <dc:date>2022-04-08T12:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593108#M206443</link>
      <description>&lt;P&gt;Here is an example of what i mean and reason i decided to revisit this topic&lt;/P&gt;&lt;P&gt;| stats avg(eval(round(TX,1))) as avg1 avg(TX) as avg2&lt;/P&gt;&lt;P&gt;output&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mal11_0-1649421854605.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/19009i0E4C65765C042A92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mal11_0-1649421854605.png" alt="mal11_0-1649421854605.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 12:45:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593108#M206443</guid>
      <dc:creator>mal11</dc:creator>
      <dc:date>2022-04-08T12:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Round in a stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593224#M206476</link>
      <description>&lt;P&gt;Not sure what the issue is here.&lt;/P&gt;&lt;P&gt;stats avg will compute the average of the values found in each event and give you an unrounded result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;stats avg(eval(round(val, 0))) will round the value before giving it to the avg() aggregation. so if you have three events with values 3.3, 3.4 and 4.4, then it will take the average of 3+3+4 (10), which will give you 3.33333333 - again, an unrounded result.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval value = split("3.3,3.4,4.4", ",")
| mvexpand value
| eventstats avg(eval(round(value, 0))) as avg
| stats avg(value) as v values(avg) as avg
| eval r_v=round(v), r_avg=round(avg)&lt;/LI-CODE&gt;&lt;P&gt;If you want to get a rounded value from your average, the round after the stats, as in the accepted solution, i.e.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you clarify what you mean by defeating the purpose&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243439"&gt;@mal11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;eval needs to go after stats operation which defeats the purpose of a the average.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 01:08:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Round-in-a-stats-command/m-p/593224#M206476</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-04-11T01:08:43Z</dc:date>
    </item>
  </channel>
</rss>

