Splunk Search

AVG command with WHERE statement

Marco_Develops
Path Finder

Hello All,

 

I am trying to calculate the Average of a column, but i want it to ignore all values that are equal to 0.

 

This currently what I have right now: 

 

stats avg(ComplianceScore) as CS by GeoLocation

 

But I need it to calculate AVG only if Compliance Score is not Zero. 

 

Thank you,

Marco

 

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Set the zeros to null so they aren't included in the average

| eval ComplianceScore=if(ComplianceScore==0,null(),ComplianceScore)
| stats avg(ComplianceScore) as CS by GeoLocation

 

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Set the zeros to null so they aren't included in the average

| eval ComplianceScore=if(ComplianceScore==0,null(),ComplianceScore)
| stats avg(ComplianceScore) as CS by GeoLocation

 

Marco_Develops
Path Finder

Thank you! Exactly What I needed... Very clever. 😀 @ITWhisperer 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I think you'll have to create a custom command to do that.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...