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!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...