Splunk Search

List top values in field b for different values in field

stephen123
Path Finder

Hi, given the following columns c1, c2 and time

c1 c2 time

a 1 10.01

a 2 10.02

a 3 10.03

b 4 10.04

b 5 10.05

b 6 10.06

c 9 10.07

c 8 10.08

c 7 10.09

I want to get the top value from each of c1, with the associated time so the out put would be

a 3 10.03

b 6 10.06

c 9 10.07

Thanks

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Usually you'd do this:

... | stats max(c2) by c1

However, that won't let you copy over the relevant timestamp... as a way out, consider something like this:

... | eventstats max(c2) as max_c2 by c1 | where c2==max_2 | dedup c1

First add max(c2) to every event, grouped by c1... then keep only the rows with the maximum... then throw out duplicates in case two events for one c1 value have identical c2 values at the maximum.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Usually you'd do this:

... | stats max(c2) by c1

However, that won't let you copy over the relevant timestamp... as a way out, consider something like this:

... | eventstats max(c2) as max_c2 by c1 | where c2==max_2 | dedup c1

First add max(c2) to every event, grouped by c1... then keep only the rows with the maximum... then throw out duplicates in case two events for one c1 value have identical c2 values at the maximum.

pradeepkumarg
Influencer

I have a similar situation where I want top three values. How can I achieve it?

stephen123
Path Finder

Both work perfect - thanks

0 Karma

HattrickNZ
Motivator

this does not show me anything in stats or visualisation, am i missing something?

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...