Splunk Search

Eventstats, eval and "category" assignment

betto86
Engager

Hi all 🙂

I need you help because I can't figure out how to solve this problem.
Suppose we have a table, made of two fields, as the one following:

Name    Value

A        1.1  
A        0.3  
A        1.9  
A        1.2  
A        0.9  
B        0.9  
B        0.9  
B        1.1  
B        1.6  

I need to create a new field (Id) in order to assign to values for each name, a sort of category following this rule:

Values with the same ID are contiguous values in range 0.7 < Value < 1.3. If the value is out of this interval, assign a new Id. When parsing a new Name value, the Id must restart from 0.

That is, I need to obtain this table:

Name    Value    Id

A        1.1     0   
A        0.3     1
A        1.9     2
A        1.2     3
A        0.9     3
B        0.9     0
B        0.9     0
B        1.1     0
B        1.6     1

This is a part of my search:

eval id = 0 |
streamstats current=t global=f window=2 first(id) as precId last(Value) as currValue  by Name |
eval id=if((currValue  > 0.7 AND currValue  < 1.3), precId, precId+1) |
table myTime,  process, destip, _time , absTmp, mediana, rapporto, id, heartId, currRapporto, precId, newId

I'm just parsing each row with streamstats, taking information from the previous row in order to know the correct Id to assign to the parsed row. But it seems not to work.

Any help or suggestion will be appreciated,

thank you guys! 🙂

Tags (1)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Consider this:

| stats count | eval foo = "A-1.1,A-0.3,A-1.9,A-1.2,A-0.9,B-0.9,B-0.9,B-1.1,B-1.6" | makemv foo delim="," | mvexpand foo | eval Name = replace(foo, "-.*", "") | eval Value = tonumber(replace(foo, ".*-", "")) | fields - count foo | eval temp = if(0.7 < Value AND Value < 1.3, 0, 1) | delta temp as delta | eval temp = if(delta == -1, 1, temp) | streamstats sum(temp) as Id by Name | fields - temp delta
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...