Splunk Search

avg value of a field based on the range of another field

Da_Vicki
Engager
Logs :

Size    ExecValue
3       400
4       200 
13      150
2       300

Output:

     Size      avg(ExecValue)   max(ExecValue)
     0-5       300              400 
     6-10      0                0
    11-15     150               150

How can i achieve the above result?

Tags (4)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Sure, you can do this:

base search | bin span=5 Size | stats avg(ExecValue) max(ExecValue) by Size | makecontinuous Size | fillnull

Here's a dummy query generating sample data to test:

| stats count | eval value = "2 3 4 13" | makemv value | mvexpand value | eval foo = random() % 100 | bin span=5 value | stats avg(foo) max(foo) by value | makecontinuous value | fillnull

Dummy output:

    value   avg(foo)  max(foo)
1     0-5 53.000000         73
2    5-10         0          0
3   10-15 95.000000         95

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Sure, you can do this:

base search | bin span=5 Size | stats avg(ExecValue) max(ExecValue) by Size | makecontinuous Size | fillnull

Here's a dummy query generating sample data to test:

| stats count | eval value = "2 3 4 13" | makemv value | mvexpand value | eval foo = random() % 100 | bin span=5 value | stats avg(foo) max(foo) by value | makecontinuous value | fillnull

Dummy output:

    value   avg(foo)  max(foo)
1     0-5 53.000000         73
2    5-10         0          0
3   10-15 95.000000         95
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...