Splunk Search

Lead\ Lag in splunk?

Yarsa
Path Finder

Hi, when I work with SQL I find the "Lead\ Lag" function very crutial.
I'm using it mostly between dates.
Does splunk supply an alternative?
thanks!

Tags (1)
0 Karma
1 Solution

Ayn
Legend

You could use streamstats (http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Streamstats ). Say you want LAG(field):

... | streamstats current=f last(field) as last_field

For LEAD, just get the results in reverse order (using reverse).

You might also want to have a look at delta which computes differences between values of a field for different events. http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Delta

View solution in original post

Ayn
Legend

You could use streamstats (http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Streamstats ). Say you want LAG(field):

... | streamstats current=f last(field) as last_field

For LEAD, just get the results in reverse order (using reverse).

You might also want to have a look at delta which computes differences between values of a field for different events. http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Delta

Yarsa
Path Finder

What if I want to lag values 7 rows apart (not just the previous one)?

0 Karma

MarioM
Motivator

what do you want to achieve? any data sample to better understand?
Have you check this link:
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...