Splunk Search

If/else conditional statements for search??

monicato
Path Finder

Is it possible to have an if else conditional statement in search? I'm creating a form with a drop-down list and depending on which option the user chooses, the results are calculated differently. I need something that will do

if $eventtype$="event1" then, calculate completion rate this way,

else, calculate completion rate another way

Can this be done? I have a form and this search will be in a

~Thanks!!

1 Solution

Ayn
Legend

What does your whole search look like, and how are you calculating things? Splunk has the eval command which either can be used by itself (| eval foo=if(eventtype="event1",somecalculation,someothercalculation)) or as part of some kind of stats command (| stats count(eval(someevalcondition)) for instance, replace with whatever statistical function you want). There's also case which lets you specify an arbitrary number of options rather than just the if statements 2 (either eventtype is this, or it isn't).

View solution in original post

Ayn
Legend

What does your whole search look like, and how are you calculating things? Splunk has the eval command which either can be used by itself (| eval foo=if(eventtype="event1",somecalculation,someothercalculation)) or as part of some kind of stats command (| stats count(eval(someevalcondition)) for instance, replace with whatever statistical function you want). There's also case which lets you specify an arbitrary number of options rather than just the if statements 2 (either eventtype is this, or it isn't).

Splunk_U
Path Finder

how to do that?

0 Karma

john
Communicator

You can try conditionalswitcher modules to switch your modules or searches on basis of user input.

0 Karma

monicato
Path Finder

ah thanks! I was looking for the if statement format! Thank you!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...