Splunk Search

How do I compare the average of the first 10 results to the average of the last 10 results and apply a calculation?

hyperscaleau
Engager

I need to return the average of the earliest 10 results (OG) in an index and the average of the latest 10 results (FG) in the same index. I then need to apply a calculation to get the result (ABV) -ie:

ABV=[average of earliest 10 results] minus [average of the latest 10 results] multiplied by 131.25

I can calculate OG by using this search:

| streamstats window=10 earliest(SG) as SGStart | stats avg(SGStart) as OG

And I can calculate FG by using this search:

| streamstats window=10 latest(SG) as SGEnd | stats avg(SGEnd) as FG

And I can also calculate ABV by appending:

| eval stepG = 'OG'-'SG' | eval ABV=stepG*131.25 | table ABV

But obviously some events are lost in the pipeline due to filtering and I can't figure out how to put it all together.

Any help would be greatly appreciated!

1 Solution

harishalipaka
Motivator

Hi @hyperscaleau

try like this

index=.................| streamstats window=10 earliest(SG) as SGStart | stats avg(SGStart) as OG |appendcols [search index=........| streamstats window=10 latest(SG) as SGEnd | stats avg(SGEnd) as FG] | eval stepG = 'OG'-'SG' | eval ABV=stepG*131.25 | table ABV
Thanks
Harish

View solution in original post

harishalipaka
Motivator

Hi @hyperscaleau

try like this

index=.................| streamstats window=10 earliest(SG) as SGStart | stats avg(SGStart) as OG |appendcols [search index=........| streamstats window=10 latest(SG) as SGEnd | stats avg(SGEnd) as FG] | eval stepG = 'OG'-'SG' | eval ABV=stepG*131.25 | table ABV
Thanks
Harish

hyperscaleau
Engager

Thanks @harishalipaka You're a star! Slight correction to due some typos (from my original post) but it works perfectly.

index=xyz| streamstats window=10 earliest(SG) as SGStart | stats avg(SGStart) as OG |appendcols [search index=xyz | streamstats window=10 latest(SG) as SGEnd | stats avg(SGEnd) as FG] | eval stepG = 'OG'-'FG'  | eval ABV = 'stepG'*131.25 | table OG,FG,ABV
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...