Splunk Search

show percentage as a new field

ranjitbrhm1
Communicator

Hello All, I have a question for you. We have data where the user want to calculate the number of events that have occured for an event name. so i write a query (Just an example)
index=_internal | stats count(sourcetype) as number by name
and i get a result like this
name number
asdf 10
ghjoi 15
kdkd 20

i want to have a third field somehow where it shows that asdf occured 30% ghjoi occured 50% and kdkd occured 20%

name number final percentage
asdf 10 30
ghjoi 15 50
kdkd 20 20

how do i achieve this?

thanks

Tags (2)
0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi @ranjitbrhm1,

Based on example you have given , can you please try like this

index=_internal | stats count(sourcetype) as number by name
| eventstats sum(number) AS total
| eval percentage=(number/total)*100

View solution in original post

harsmarvania57
Ultra Champion

Hi @ranjitbrhm1,

Based on example you have given , can you please try like this

index=_internal | stats count(sourcetype) as number by name
| eventstats sum(number) AS total
| eval percentage=(number/total)*100

ranjitbrhm1
Communicator

absolutely brilliant. it worked like a charm. thanks XOXO

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!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...