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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...