Splunk Search

Why does the case statement works until an AND is added to it?

azvargas
Loves-to-Learn

When I have this case statement like this, it "works". It runs and puts values in the iSeries column, but they are wrong.

| eval Platform=case((source="A" OR source="B" OR source="C") , "iSeries", true(),"Other")

When I add an AND to it so that it fulfills the true condition, no values are put in the iSeries column, and everything goes to Other.

| eval Platform=case((source="A" OR source="B" OR source="C") AND (dest=X OR dest=Y OR dest=Z), "iSeries", true(),"Other")

What am I doing wrong?

Labels (1)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

Is your dest X or "X"?

| makeresults
| eval source="A", dest="X"
| eval Platform=case((source="A" OR source="B" OR source="C") AND (dest="X" OR dest="Y" OR dest="Z"), "iSeries", true(),"Other")

 

to4kawa
Ultra Champion

In eval statement,

dest=x means the field dest equals the field x.
As @isoutamo says, you need quotes.

0 Karma

azvargas
Loves-to-Learn

I've tried with and without quotes, and it still doesnt work.

0 Karma

to4kawa
Ultra Champion

>It runs and puts values in the iSeries column.

your working query puts "iSeries" text on Platform field(column).

>it still doesnt work.
what's your expected result?


0 Karma

azvargas
Loves-to-Learn

Correct, my query puts "iSeries" text in the Platform field.  But it only works without the AND clause, but this is not the right condition.  I need it to work with the AND clause portion.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Can you print dest and X etc. if those are fields and not values?

0 Karma

azvargas
Loves-to-Learn

Can you print dest and X etc. if those are fields and not values?

Not sure how to do this.  Its a long query.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

e.g.

| makeresults
| eval foo="A", bar=foo
| eval foobar= "'" . foo . "' '" . bar . "'"
| table foo bar foobar
0 Karma

azvargas
Loves-to-Learn

I'd like to add that I have had this same criteria for close to a year in a dashboard just not in a case statement and it works.  

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

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