Splunk Search

round fuction usage for avg command output

rakesh_498115
Motivator

Hi ,

I have been using the stats avg(duration) as Avg_Duration in my query.But while displayin the Avg_Duration i am getting the output value with 6 decimal digits after the precision.Something like 2.123456 i would like to round it off to four digits only.Tried using the round function along with the stats command..but it didnt worked.

Please help me on this .Thanx

Tags (2)
1 Solution

Drainy
Champion

What have you tried already when you tried to round?
Something like this works with my setup;

| stats avg(duration) as Avg_duration | eval Avg_duration=round(Avg_duration,0)

View solution in original post

damiensurat
Contributor

I know this has been around a while, but I felt I should share this with the community. You can incorporate the eval statement into the stats command:
EG:
| stats avg(eval(round(duration,0))) AS Avg_Duration

[https://docs.splunk.com/Documentation/Splunk/7.2.5/Search/Usestatswithevalexpressionsandfunctions]

This especially works well when you are using a split by statement.
EG:
| stats avg(eval(duration(count,0))) AS Avg_Duration by something

0 Karma

emikulic
Explorer

It would be a lot better inline. I tried but as such in our 6.1.2 server cannot it does not work. ie.

 | stats round(avg(duration),0) 

Drainy
Champion

What have you tried already when you tried to round?
Something like this works with my setup;

| stats avg(duration) as Avg_duration | eval Avg_duration=round(Avg_duration,0)
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...