Splunk Search

How can I get the previous value of the field that I'm computing in my eval

pradeepkumarg
Influencer

I'm computing a field using eval statement and in the same eval I want to check what is the value for the same field in previous event

Apparently I need autoregress on the same field which I'm computing currently. (fieldA in the below example)

|eval fieldA = if(prev_fieldA=fieldB,"Y","N")
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

You can copy over neighbouring field values using streamstats:

... | streamstats current=f window=1 last(fieldA) as prev_fieldA | ...

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

You can copy over neighbouring field values using streamstats:

... | streamstats current=f window=1 last(fieldA) as prev_fieldA | ...

martin_mueller
SplunkTrust
SplunkTrust

prev_fieldA is the neighbouring value of fieldA. Run this dummy query to see for yourself:

| stats count as fieldA | eval fieldA = "a b c d d e f" | makemv fieldA | mvexpand fieldA | streamstats current=f window=1 last(fieldA) as prev_fieldA | eval equal = if(fieldA==prev_fieldA, "yes", "no")

pradeepkumarg
Influencer

How can I club the above statement where I'm actually computing fieldA ?

prev_fieldA determines the current fieldA

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...