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
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...