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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...