Splunk Search

How to return the most recent 2 values of X by Y?

the_wolverine
Champion

Stats can be used to get the most recent X value of Y, for example:
| stats latest(x) by y

How do I get the most recent 2 values of X by Y for comparing change in the value of X.

0 Karma
1 Solution

somesoni2
Revered Legend

Try this

your base search
| dedup 2 y
| stats latest(x) as Current earliest(x) as Previous by y

View solution in original post

niketn
Legend

@the_wolverine, Try the following run anywhere search based on Splunk's _internal index (x is date_second and y is component)

index="_internal" sourcetype="splunkd" log_level!="INFO" component!="ConfContentsCache"
| stats list(date_second) as date_second by component
| eval latest=mvindex(date_second,0), previous=mvindex(date_second,1)
| fillnull value=0 latest previous
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

somesoni2
Revered Legend

Try this

your base search
| dedup 2 y
| stats latest(x) as Current earliest(x) as Previous by y

the_wolverine
Champion

You Rock!

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...