Splunk Search

If one field null, populate another field with 0

cooperjaram
Engager

Hello Splunkers,

I have two fields that correlate. One field is hostname and another field is score. When I try to get an average of the score I get a incorrect value due to it calculating the score field even though the hostname is null and not representing anything. Is there a way to use if(isnull) or any other eval command so if hostname is null, it gives the other field the value of 0?

Thanks,

Cooper

0 Karma

to4kawa
Ultra Champion
your search
|stats avg(eval(if(isnull(hostname), null(), score))) as score_avg
0 Karma

skoelpin
SplunkTrust
SplunkTrust

Without seeing your results, it would look something like this

| eval hostname=if(isnull(score),0,'hostname')
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...