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!

AI for AppInspect

We’re excited to announce two new updates to AppInspect designed to save you time and make the app approval ...

App Platform's 2025 Year in Review: A Year of Innovation, Growth, and Community

As we step into 2026, it’s the perfect moment to reflect on what an extraordinary year 2025 was for the Splunk ...

Operationalizing Entity Risk Score with Enterprise Security 8.3+

Overview Enterprise Security 8.3 introduces a powerful new feature called “Entity Risk Scoring” (ERS) for ...