Splunk Search

How do I round only certain columns/fields ?

HattrickNZ
Motivator

How do I round only certain columns/fields ?
below this | foreach * [eval <<FIELD>>=round('<<FIELD>>',2)] will round all the fields to 2 decimal places.
How do I do it for just fields that start with kpi

I was thinking something like this,
| foreach * [eval <<kpi*>>=round('<<kpi*>>',2)]
but I think there might be more to it. Can you advise?

sample data search:

| makeresults 
 | eval data = "
  1-Sep    0 55.5555 57.7777;
  2-Sep    0 56.6666 58.8888; 
  " 
 | makemv delim=";" data 
 | mvexpand data 
 | rex field=data "(?<Date>\d+-\w+)\s+(?<Other1>\d+)\s+(?<kpi2>\d+(\.\d+)?)\s+(?<kpi3>\d+(\.\d+)?)" 
 | fields + Date Other1 kpi2 kpi3
 | search Other1=*
 | foreach * [eval <<FIELD>>=round('<<FIELD>>',2)]
Tags (2)
0 Karma
1 Solution

HattrickNZ
Motivator

shoot, think I worked that out as I asked the question.

| foreach kpi* [eval <<FIELD>>=round('<<FIELD>>',2)]

View solution in original post

0 Karma

HattrickNZ
Motivator

shoot, think I worked that out as I asked the question.

| foreach kpi* [eval <<FIELD>>=round('<<FIELD>>',2)]

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...