Splunk Search

How to create difference of two values

reverse
Contributor

Q1: How can I get c4 where c4 will always be the difference of values in c3 against max of c2 - min of c2

For example: Here c4 for A = 677-76

Please guide.

c    c2   c3
A   1   76
A   2   7
A   3   6
A   4   677
B   1   65
B   2   675
B   3   90
B   4   78
C   1   121
C   2   56
C   3   54
C   4   67
D   1   56
D   2   6
D   3   5
D   4   657
Tags (3)
0 Karma
1 Solution

Vijeta
Influencer

@reverse

 <your query>| sort c c2
  | stats first(c3) as first, last(c3) as last by c 
  | eval c4=last - first

View solution in original post

0 Karma

Vijeta
Influencer

@reverse

 <your query>| sort c c2
  | stats first(c3) as first, last(c3) as last by c 
  | eval c4=last - first
0 Karma

reverse
Contributor

This worked but i had to add eventstats. .. was getting blank with stats

0 Karma

Vijeta
Influencer

Good to know. Thanks

0 Karma

reverse
Contributor
0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

Try something like this:

index="yourindex" sourcetype="yoursourcetype" 
| stats max(c3) as max min(c3) as min by c 
| eval c4=max-min
0 Karma

reverse
Contributor

Please see the example

0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

Is this what you were looking for?

index="yourindex" sourcetype="yoursourcetype" 
| eventstats min(c3) as min max(c3) as max by c 
| eval c4=max-min 
| table c c2 c3 c4 
| sort c c2

reverse
Contributor

This is not producing the intended results

0 Karma

reverse
Contributor

@Vijeta please guide.

0 Karma

Vijeta
Influencer

@reverse try using delta command and see if that works.

0 Karma

reverse
Contributor

Tried that .. it is continuing for all rows .. i want it by c1.. delta is not taking by clause

0 Karma

Vijeta
Influencer

@reverse ok I see you changed the question. Try below

<your query>
 | stats max(c3) as max, min(c3) as min by c 
 | eval c4=max-min
0 Karma

reverse
Contributor

Not producing the intended result..

0 Karma

reverse
Contributor

I need the difference of c2 against c3 values as mentioned in the example

0 Karma

reverse
Contributor

Could you please post an example.. dont know that command..thank you

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...