Splunk Search

Unable to use case with stats

mohankesireddy
Path Finder

Hi Everyone, I am not able to use eval command with stats. I am using the following search in a form, I want to find the sum of a field depending on the action selected from drop down. I am using the eval command to find the field but not able the pass the same to stats command.

Any help is much appreciated..

sourcetype=brm_batch_data ACTION=$ACTION_SELECTED$ | eval action_val = case (ACTION == "INVOICING", "BILL_DUE", ACTION == "BILLING", "AMOUNT", ACTION="PAYMENT", "AMOUNT") | stats sum(action_val)

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

Well, since action_val is not a number, it is not meaningful to try sum it, obviously. Perhaps you have fields/variables named BILL_DUE and AMOUNT, in which case all you need to do is remove the quotes from around the names in your case() expression to fix it.

 sourcetype=brm_batch_data ACTION=$ACTION_SELECTED$  | eval action_val = case (ACTION == "INVOICING", BILL_DUE, ACTION == "BILLING", AMOUNT, ACTION="PAYMENT", AMOUNT) | stats sum(action_val)

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

Well, since action_val is not a number, it is not meaningful to try sum it, obviously. Perhaps you have fields/variables named BILL_DUE and AMOUNT, in which case all you need to do is remove the quotes from around the names in your case() expression to fix it.

 sourcetype=brm_batch_data ACTION=$ACTION_SELECTED$  | eval action_val = case (ACTION == "INVOICING", BILL_DUE, ACTION == "BILLING", AMOUNT, ACTION="PAYMENT", AMOUNT) | stats sum(action_val)

mohankesireddy
Path Finder

thanks gkanapathy. it worked....

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 ...