Splunk Search

How to add + or - before a percentage?

jip31
Motivator

hello

I use the search below in order to calculate a percentage

But I need to add + if s > s2 and - if s2 < s

How to do this please?

 

`index` sourcetype="session" 
| bin _time span=15m 
| eval time=strftime(_time,"%H:%M") 
| stats dc(s) as s by time 
| table s
| appendcols 
    [ search `index` sourcetype="session" earliest=-7d@d+7h latest=-7d@d+19h 
    | bin _time span=15m 
    | eval time=strftime(_time,"%H:%M") 
    | stats dc(s) as s2 by time  
    | table s2] 
| eval perc=round((s/s2)*100,1). "%" 
| table perc

 

 

Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

@jip31,

I suppose that the problem is the plus (+)  mark because the minus (-) mark is always inserted in the eval calculation.

Anyway, you could modify your eval command in this way:

| eval perc=if(s>s2,"+","").round((s/s2)*100,1)."%"

Ciao.

Giuseppe

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

if s > s2 is the same as if s2 < s

0 Karma

gcusello
SplunkTrust
SplunkTrust

@jip31,

I suppose that the problem is the plus (+)  mark because the minus (-) mark is always inserted in the eval calculation.

Anyway, you could modify your eval command in this way:

| eval perc=if(s>s2,"+","").round((s/s2)*100,1)."%"

Ciao.

Giuseppe

0 Karma

jip31
Motivator

Hi Gcusello

thanks

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jip31,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the Contributors 😉

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 ...