Splunk Search

Return "Yes" if field exists in another field in the table

nanuli
Engager

Hello! I have run a search which results in displaying a table. In this table, I would like to check if a combination of values between two fields exists, and, if so, return "Yes." I have done this in PowerBI using the following command, but I am unsure how to do it in SPL.

VAR _SEL =

SELECTCOLUMNS('table1', "code1", [code1])

RETURN IF ('table1'[code2] IN _SEL, "Yes", "No")

 

An example initial table is below:

id, code1, code2

1, ab, cd

2, cd, de

3, ab, hi

4, cd, ab 

5, jk, cd

6, hi, jk

7, jk, hi

The result I am looking for is that it will find that the combination of ab+cd and hi+jk exists in both directions (code1, code2 and code2, code1). 

id, code1, code2, result

1, ab, cd, yes

2, cd, de, no

3, ab, hi, no

4, cd, ab, yes 

5, jk, cd, no

6, hi, jk, yes

7, jk, hi, yes

Thank you for your help!

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Always best to fully describe your problem giving as much sufficient detail as possible.

Try this

| eval codes=mvsort(mvappend(code1, code2))
| eventstats count by codes
| eval result=if(count==2, "yes", "no")

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval result=if((code1=="ab" AND code2=="cd") OR (code1=="cd" AND code2=="ab"), "yes", "no")
0 Karma

nanuli
Engager

Hello @ITWhisperer . Thank you for the quick response. I have updated my post. There are multiple potential combinations--not just ab and cd--so the actual combination cannot be defined. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Always best to fully describe your problem giving as much sufficient detail as possible.

Try this

| eval codes=mvsort(mvappend(code1, code2))
| eventstats count by codes
| eval result=if(count==2, "yes", "no")
0 Karma

nanuli
Engager

Thank you so much, @ITWhisperer . That did the trick! 

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...