Splunk Search

conditional average

andreaswpv
Explorer

Hi 

need to calculate the average based on a condition. 

  • testing=true vs testing=false  (lets say field A)
  • field B has the values to average (milliseconds)
  • field C has urls 

something like this:

| stats avg(fieldB, when field A testing true) as trueV avg(fieldB, when field A testing false) as falseV by Field C

Goal is a table like this:

url  | average (true) | average( false).

 

 

 

Labels (1)
Tags (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval trueA=if(fieldA=true,fieldB,null())
| eval falseA=if(fieldA=true,null(),fieldB)
| stats avg(trueA) as trueV avg(falseA) as falseV by fieldC

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval trueA=if(fieldA=true,fieldB,null())
| eval falseA=if(fieldA=true,null(),fieldB)
| stats avg(trueA) as trueV avg(falseA) as falseV by fieldC

andreaswpv
Explorer

Thanks, that works. Now I understand this - this is making two separate 'fields' based on the condition, to avoid having the calculation either in the eval, or in the stats (which both don't work). 

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...