Splunk Search

Can you help me with a search involving multiple AND conditions in eval w/ if statement?

blindfire_bandi
Explorer

Hello there from someone in healthcare it industry.

I'm working with multiple conditions, and I want to make sure my syntax is correct here.

| eval goodClaimStat = if((catCode != "E0") and (catCode != "E1") and (catCode != "E2") and (catCode != "E3") and (catCode != "E4") and (catCode != "D0"), "true", "false")
| eval goodEligOrAuth = if(tripleA != "42" and tripleA != "80", "true", "false")
 | eval successTransaction = if((transactionState == "Success" and goodClaimStat == "true" and goodEligOrAuth == "true"), 1, 0)

catCode, tripleA and transactionState are all fields that I extracted from events using rex(). I verified in search that I'm extracting them correctly, so the next part of my query is this decision logic. I'm assuming that this is where my problem lies. transactionState has to be "Success" and then, catCode and tripleA cannot equal those values above, respectively.

0 Karma
1 Solution

woodcock
Esteemed Legend

No, that is wrong. You must UPPER-CASE your boolean operators, and it is best to use == logic, rather than != logic like this:

... | eval goodClaimStat = if(((catCode == "E0") OR (catCode == "E1") OR (catCode == "E2") OR (catCode == "E3") OR (catCode == "E4") OR (catCode == "D0")), "false", "true")
| eval goodEligOrAuth = if(((tripleA == "42") OR (tripleA == "80")), "false", "true")
| eval successTransaction = if(((transactionState == "Success") AND (goodClaimStat == "true") AND (goodEligOrAuth == "true")), 1, 0)

Notice my extended use of parentheses. This helps because eventually you will be mixing AND, OR, and NOT and it won't work correctly.

View solution in original post

woodcock
Esteemed Legend

No, that is wrong. You must UPPER-CASE your boolean operators, and it is best to use == logic, rather than != logic like this:

... | eval goodClaimStat = if(((catCode == "E0") OR (catCode == "E1") OR (catCode == "E2") OR (catCode == "E3") OR (catCode == "E4") OR (catCode == "D0")), "false", "true")
| eval goodEligOrAuth = if(((tripleA == "42") OR (tripleA == "80")), "false", "true")
| eval successTransaction = if(((transactionState == "Success") AND (goodClaimStat == "true") AND (goodEligOrAuth == "true")), 1, 0)

Notice my extended use of parentheses. This helps because eventually you will be mixing AND, OR, and NOT and it won't work correctly.

blindfire_bandi
Explorer

That worked like a charm. Thank you so much.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...