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

 

 

Labels (1)
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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...