Splunk Search

How to round the output from chart command?

kiril123
Path Finder

Hello,

I have produced a table which shows distances between the cities. The search is shown below:

my search | chart  avg(distance) by from_city, to_city

However the distances are shown as floating point numbers with 15 digits after the point. I want to round the number to only 1 digit after the point.

I have tried applying the round function as shown below but this didn't change anything:

my search | chart  avg(distance) by from_city, to_city | eval round(distance,1)

Do you have any suggestions?

Tags (3)
1 Solution

p_gurav
Champion

Try this:

my search | chart  avg(distance) as distance by from_city, to_city | eval distance=round(distance,1)

Note: Rename field if you want to perform eval operation on it.

View solution in original post

p_gurav
Champion

Try this:

my search | chart  avg(distance) as distance by from_city, to_city | eval distance=round(distance,1)

Note: Rename field if you want to perform eval operation on it.

kiril123
Path Finder

Thank you but this still doesn't round the numbers.

0 Karma

p_gurav
Champion

Try putting eval inside chart command as:

my search| chart  eval(round(avg(distance),1)) as distance
0 Karma

bwlm
Path Finder

thank you, that additional eval() worked. It was so frustrating that the "round()" and "floor()" commands can be used like this in a stats function or eval the field after the stats function... but with the chart functions they are charted immediately and simple function wrapping without "eval()" is not accepted as valid by the chart commands.

0 Karma

kiril123
Path Finder

This has worked. Thank you!

0 Karma
Get Updates on the Splunk Community!

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...