Splunk Search

Events with maximum value of dynamic field

mmclain1
Explorer

I think I'm missing something. I have rex generating a new field for me. I want to return only events with the maximum value for that field. Let's say the field is called testfield and the possible values for that field are 1, 2, or 3. I want to return only events with testfield=3. However, this will be in a dashboard and the next time it runs, the max value could be 4. How do I do this?

Tags (3)
1 Solution

sideview
SplunkTrust
SplunkTrust

Here's something that should work for you.

<your searchterms> | eventstats  max(testfield) as max | where testfield=max | fields - max

eventstats works much like its bigger brother stats, except that it paints its statistics back onto the original rows that were input, rather than aggregating/transforming the set. This generally means that it puts its stats back on the 'events' (although not necessarily - you can get good use out of eventstats further down the search pipeline sometimes too)

And if you're not actually interested in just the raw event text, but rather in one or more fields that are on those events, then a more straightforward way might be to do this:

<your searchterms> | stats max(someField) values(someOtherField) avg(someThirdField) by testField | sort - testField | head 1

View solution in original post

sideview
SplunkTrust
SplunkTrust

Here's something that should work for you.

<your searchterms> | eventstats  max(testfield) as max | where testfield=max | fields - max

eventstats works much like its bigger brother stats, except that it paints its statistics back onto the original rows that were input, rather than aggregating/transforming the set. This generally means that it puts its stats back on the 'events' (although not necessarily - you can get good use out of eventstats further down the search pipeline sometimes too)

And if you're not actually interested in just the raw event text, but rather in one or more fields that are on those events, then a more straightforward way might be to do this:

<your searchterms> | stats max(someField) values(someOtherField) avg(someThirdField) by testField | sort - testField | head 1

mmclain1
Explorer

Perfect, that's exactly what I was trying to figure out how to do! Thanks!

0 Karma

rodrigo_santos
Explorer

Great... 😄

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...