Splunk Search

Unable to find percentage of two values stored in two separate fieldnames

sh254087
Communicator

I'm facing a weird issue. I'm not able to calculate percentage value when I use two variables/fields.

I have a lookup file which looks something like - 

sl,Service,x_value

1,X,0.211

2,other,0.190

3,Y,0

4,X,0.200

5,other,0.220

I'm trying to get two columns in my resultant table to show total by service and percentage by service, respectively.
I've tried this - 

sh254087_0-1690536465779.png
percentage needs to be calculated using 2 fields whereas perc1 and perc2 are substituted with one of those two field values.

While the perc1 and perc2 gets processed and displayed, percentage doesn't show up.

I'm not sure what is that I'm doing wrong here. Can somebody please help?

Labels (5)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| inputlookup xyz.csv
| stats sum(x_value) as TotalMain by Service
| eventstats sum(TotalMain) as Total
| eval percentage=100*TotalMain/Total

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| inputlookup xyz.csv
| stats sum(x_value) as TotalMain by Service
| eventstats sum(TotalMain) as Total
| eval percentage=100*TotalMain/Total

sh254087
Communicator

This just worked perfectly. Thank you very much, @ITWhisperer .

I had never used eventstats practically. Will check more on it. 

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...