Splunk Search

Output fields based on values(current row) and values(previous row)

yuming1127
Path Finder

Hi,

Im looking a way to eval values between 2 subsequence row. Please take a look on below.


my statictis table:

Product quality
phone_a40
phone_b50
phone_c40
phone_d70


Expected output:

Product qualityscore_current_vs_previous
phone_a40 
phone_b5010
phone_c40-10
phone_d7030


As you can see, the score_current_vs_previous= quality(current row) - quality(previous row)

Appreciate your help, thanks.

Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

See this example search using your data set. What you need is from streamstats command

| makeresults
| eval _raw="Product	quality
phone_a	40
phone_b	50
phone_c	40
phone_d	70"
| multikv forceheader=1 
| table Product quality
| streamstats window=1 current=f first(quality) as prev_quality
| eval score_current_vs_previous=quality-prev_quality
| table Product quality score_current_vs_previous

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

See this example search using your data set. What you need is from streamstats command

| makeresults
| eval _raw="Product	quality
phone_a	40
phone_b	50
phone_c	40
phone_d	70"
| multikv forceheader=1 
| table Product quality
| streamstats window=1 current=f first(quality) as prev_quality
| eval score_current_vs_previous=quality-prev_quality
| table Product quality score_current_vs_previous

yuming1127
Path Finder

Great one thanks

0 Karma
Get Updates on the Splunk Community!

New Year. New Skills. New Course Releases from Splunk Education

A new year often inspires reflection—and reinvention. Whether your goals include strengthening your security ...

Splunk and TLS: It doesn't have to be too hard

Overview Creating a TLS cert for Splunk usage is pretty much standard openssl.  To make life better, use an ...

Faster Insights with AI, Streamlined Cloud-Native Operations, and More New Lantern ...

Splunk Lantern is a Splunk customer success center that provides practical guidance from Splunk experts on key ...