Splunk Search

Splunk eval not working with generated column

timcolpo
Explorer

Need some help on some Splunk Search Syntax.

| inputlookup defect__kvs
| search (week_date="") (type="") (sub_type="") (model="") (sub_type=) (model=)
| eval total_polulation=700 (this will be a $token$ in a panel)
| stats count by failure sw_type
| rename count as num_failure

| eval pct_of_total=(num_failure/total_population) | table failure sw_type num_failure pct_of_total

pct_of_total does not produce a value.

I do not want to do appendcols or a subsearch as the Token is to be widely used and it works in other queries as a variable. Total_polulation cannot be derived from the Event Set.

Basically the totals are derived in the following XML

Tags (1)
0 Karma

knielsen
Contributor

is eval total_polulation copied from your actual query? If so, then your problem is the typo in it.

I just tried what you did with some other data/fields, and it works for me.

0 Karma

timcolpo
Explorer

Thank for your response. Actually this was not a typo as I was editing the search to remove customer information. I did manage to get it to work but it was strange, for if I place the "|eval a=700" before the stats statement it does not compute, but after it it does. This was the final query.

THIS DOES NOT WORK

| inputlookup defect__kvs 
| search (week_date="*") (type="*") (sub_type="*") (model="*") (sub_type="*") (model="*") 
| eval total_population=700 | stats count by failure sw_type | rename count as num_failure
| eval pct_of_total=(num_failure/total_population) 
| rename count as num_failure | table failure sw_type num_failure pct_of_total

THIS DOES WORK

| inputlookup defect__kvs 
| search (week_date="*") (type="*") (sub_type="*") (model="*") (sub_type="*") (model="*") 
| stats count by failure sw_type | rename count as num_failure
| eval total_population=700
| eval pct_of_total=(num_failure/total_population) 
| rename count as num_failure | table failure sw_type num_failure pct_of_total
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...