Splunk Enterprise Security

Coalesce two fields with null values

lxm30
New Member

I have two fields and if field1 is empty, I want to use the value in field2. (i.e. I never want to use field2 unless field1 is empty).

I was trying to use a coalesce function but it doesn't work well with null values.

Do I have any options beyond using fillnull for field2 with a value of *, coalescing the two and then using rtrim to get rid of the star?

0 Karma
1 Solution

martinpu
Communicator

Try this

|eval field3=case(isNotNull(field1),field1,isNotNull(field2),field2,1=1, NULL)

should return field 3 as field1 if it isnt null,field2 if that isnt null and field1 is null and NULL if both are NULL

View solution in original post

0 Karma

martinpu
Communicator

Try this

|eval field3=case(isNotNull(field1),field1,isNotNull(field2),field2,1=1, NULL)

should return field 3 as field1 if it isnt null,field2 if that isnt null and field1 is null and NULL if both are NULL

0 Karma

lxm30
New Member

This works great - thanks so much for the quick response!

0 Karma

lxm30
New Member

(By * I mean some value, not necessarily the character "*").

0 Karma
Get Updates on the Splunk Community!

Index This | What did the zero say to the eight?

June 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...