Splunk Search

How to show fields conditionally in search?

djoobbani
Path Finder

Dear Splunk Community:

I have the following search query:

<Basic_Search> | chart count by path_template, http_status_code | addtotals fieldname=total
| foreach 2* 3* 4* 5* [ eval "percent_<<FIELD>>"=round(100*'<<FIELD>>'/total,2),
"<<FIELD>>"=if('<<FIELD>>'=0 , '<<FIELD>>', '<<FIELD>>'." (".'percent_<<FIELD>>'."%)")] | fields - percent_* total 2* 3* 4*

Attached is the screen result of the above query which shows the 500s columns.

I need to modify the above search so that it only displays the numbers where the percentage is great than 0.01%. How do i do that?

Thanks!

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Change the foreach statement to do this

    [ eval "percent_<<FIELD>>"=round(100*'<<FIELD>>'/total,2),
        "<<FIELD>>"=case('<<FIELD>>'=0 , '<<FIELD>>', 'percent_<<FIELD>>'>0.01, '<<FIELD>>'." (".'percent_<<FIELD>>'."%)", true(), null())] 

i.e the percentage threshold of 0.01 or above will allow the value to be shown, otherwise it will clear it

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Change the foreach statement to do this

    [ eval "percent_<<FIELD>>"=round(100*'<<FIELD>>'/total,2),
        "<<FIELD>>"=case('<<FIELD>>'=0 , '<<FIELD>>', 'percent_<<FIELD>>'>0.01, '<<FIELD>>'." (".'percent_<<FIELD>>'."%)", true(), null())] 

i.e the percentage threshold of 0.01 or above will allow the value to be shown, otherwise it will clear it

djoobbani
Path Finder

Thank you!

0 Karma

djoobbani
Path Finder

You rock, thanks this works!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...