Splunk Search

how to sum two fields with empty values in some values of one field

Ahmedkhalil
Path Finder

Hello,

i have two fields and want to sum values of them in new field as below

new field = field1 + field2
i have added below expression in props.conf

EVAL-sum_Acct_input= (field1*4)+(field2/1073741824)
problem is that i found event coverage of new field sum_acct_input = event coverage of field1 as field one not exist in all events ( it has empty values ) so how can i overcome this issue ? and also how to make this expression at index time not search time

Tags (1)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

You can utilize "coalesce" function to handle empty/null values of field 1 like below

props.conf

EVAL-sum_Acct_input = (coalesce(field1,0)*4+(field2/1073741824)

Per my knowledge, calculated fields can't be created during index time.

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

You can utilize "coalesce" function to handle empty/null values of field 1 like below

props.conf

EVAL-sum_Acct_input = (coalesce(field1,0)*4+(field2/1073741824)

Per my knowledge, calculated fields can't be created during index time.

martin_mueller
SplunkTrust
SplunkTrust

coalesce(field1, field2) is a nicer way of writing if(isnotnull(field1), field1, field2) - basically, "take the first field from the list of arguments that isn't null".

Ahmedkhalil
Path Finder

thanks alot for your help i tested it and worked fine but may i know what excatly coalesce do ?

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud | Unified Identity - Now Available for Existing Splunk ...

Raise your hand if you’ve already forgotten your username or password when logging into an account. (We can’t ...

Index This | How many sides does a circle have?

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

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...