Splunk Search

case and isnull for multiple fields

subtrakt
Contributor

HI,

Working on a query that if one field is null then it uses another field and if that field isnull it uses another. Will case work like that in a linear operation left-to-right or is there a better option?

eval main=case(isnull(test1),test2,test1,isnull(test2),test3,test2,isnull(test3),test4,test3,1=1,"All Test Are Null)

Tags (2)
0 Karma
1 Solution

vasanthmss
Motivator

Try this,

| eval main = case(isnotnull(test1), test1, isnotnull(test2), test2, isnotnull(test3), test3, isnotnull(test4), test4, 1=1 , "All Test Are Null")

Main's value should be test1 / test2 / test3 / test4 in-case test1 is empty option goes to test2, if test2 is empty then option goes to test 3 and test4 like wise.

If suppose test1, test2, test3, test4 contains value then test1 would be assigned to main. if not "All Test are Null" will be assigned to main.

Hope this will help you.

V

View solution in original post

davebrooking
Contributor

Take a look at the eval coalesce function - as the documentation states

This function takes an arbitrary number of arguments and returns the first value that is not null.

0 Karma

vasanthmss
Motivator

Try this,

| eval main = case(isnotnull(test1), test1, isnotnull(test2), test2, isnotnull(test3), test3, isnotnull(test4), test4, 1=1 , "All Test Are Null")

Main's value should be test1 / test2 / test3 / test4 in-case test1 is empty option goes to test2, if test2 is empty then option goes to test 3 and test4 like wise.

If suppose test1, test2, test3, test4 contains value then test1 would be assigned to main. if not "All Test are Null" will be assigned to main.

Hope this will help you.

V

subtrakt
Contributor

Thanks - worked like a dream

0 Karma

vasanthmss
Motivator

Cheers !!!

V
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...