Splunk Search

How to get the percentage using values in event over two columns?

splunker1981
Path Finder

Hello Splunk masters

I am trying to figure out how to get a rate (percent) by looking at two strings within a column, then dividing by values in another column

Sample data below.  What I'm trying to do is calculate the rate of "incomplete" by batch week.  Rate is calculated by taking the batch week, getting the total = (complete + incomplete) / incomplete.  As shown below, I included a sample of what I'd like to get as a final output.  This is way beyond my Splunk-fu and hoping someone can help me out here.   Thanks for the help in advanced

 

 

 

Sample Data
site	batch_status	batch_week	status_count
2506	complete	      16	      7
2506	incomplete	      16	      4
2506	complete	      17	      5
2506	incomplete	      17	      3
2506	complete	      18	      2
2506	incomplete	      18	      4

			
What I'd like to get back			
2506	incomplete	16	36%
2506	incomplete	17	38%
2506	incomplete	18	-66%

 

 

 

 

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @splunker1981,

please see my approach and adapt it to your needs:

<your_search
| stats 
   sum(eval(if(batch_status="complete",status_count,0))) AS complete
   sum(eval(if(batch_status="incomplete",status_count,0))) AS incomplete
   BY site batch_week
| eval perc=((complete+incomplete)/incomplete)."%"
| table site batch_week incomplete perc

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @splunker1981,

please see my approach and adapt it to your needs:

<your_search
| stats 
   sum(eval(if(batch_status="complete",status_count,0))) AS complete
   sum(eval(if(batch_status="incomplete",status_count,0))) AS incomplete
   BY site batch_week
| eval perc=((complete+incomplete)/incomplete)."%"
| table site batch_week incomplete perc

Ciao.

Giuseppe

0 Karma

splunker1981
Path Finder

Thanks a bunch! That did the trick

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @splunker1981,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

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!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...