Splunk Search

How do you do a conditional Eval?

marjonhtuazon
Explorer

The scenario is this.

I have a two field name name joe and bob. if bob help a job it indicate yes as its field value
like this joe="y" and if bob help with a job it will have a value of bob="y" and "n" if they didnt help.

JOE     BOB
Y            N
Y            N
Y           N
N           Y
N           Y

now im trying to make a single field name "assistance" that counts if joe,bob or both of them help in the job

I use:

 |eval  assistance=if(joe="y" AND bob="y", "both",(if(joe="y", "JOE Only", "BOB Only")))

assistance COUNT
JOE Only - 3

BOB only - 2

both -------- 0

but if I evaluate it, and the result of BOTH is "0", the field "BOTH" never showed when i tabled "assistance". But I NEED the field BOTH to show up so i can show in data visualization that they didn't assist each other.

Tags (2)

woodcock
Esteemed Legend

Like this:

You Existing Search Here
| stats count(eval(Joe=="Y")) AS Joe_Only count(eval(Bob=="Y")) AS Bob_Only count(eval(Joe=="Y" AND Bob=="Y")) AS Both
| transpose column_name=assistance
| rename "row 1" AS COUNT

Here is a run-anywhere example:

|makeresults | eval raw="Y,N Y,N Y,N N,Y N,Y"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?<Joe>.*?),(?<Bob>.*)$"
| stats count(eval(Joe=="Y")) AS Joe_Only count(eval(Bob=="Y")) AS Bob_Only count(eval(Joe=="Y" AND Bob=="Y")) AS Both
| transpose column_name=assistance
| rename "row 1" AS COUNT
0 Karma

marjonhtuazon
Explorer

thanks for a work around but unfortunately i cant use it to troubleshoot my error on my search query. like if I pipe another search the results always end up on "No search Results" and i dont know why. I need to correlate this output to another data so i can have a good data visualization
but thanks anyway

0 Karma

woodcock
Esteemed Legend

This is not a work-around, it is EXACTLY what you asked.

skoelpin
SplunkTrust
SplunkTrust

Why give up so easy? Start stripping lines off and seeing whats broke

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...