Splunk Search

Comparing individual values with the past average

MidnightRun
Explorer

I have a search query that looks like this:

 

index="myindex" sourcetype="mysource" earliest=@d latest=now  
| append [ search index="myindex" sourcetype="mysource" earliest=-1mon@mon latest=@mon 
| stats avg(Price) as past_avg by ID ] 
| stats values(*) as * by ID
| table Date, ID, Price, past_avg

This gives me:

Screenshot_1.png

what I'm trying to do is display only those values in the Price column that are smaller then past_avg,  does anyone know how I could achieve that?

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You could use mvfilter - the problem with this is that you can only reference the mv field, so you could concatenate the average, then in the filter split the two parts for the comparison, then remove the average

| eval price=mvmap(price,price."|".past_avg)
| eval price=mvfilter(mvindex(split(price,"|"),0)<mvindex(split(price,"|"),1))
| eval price=mvmap(price,mvindex(split(price,"|"),0))

Alternatively, you could do the comparison before the stats

| eventstats values(past_avg) as past_avg by id
| where price < past_avg
| stats values(*) as * by id

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You could use mvfilter - the problem with this is that you can only reference the mv field, so you could concatenate the average, then in the filter split the two parts for the comparison, then remove the average

| eval price=mvmap(price,price."|".past_avg)
| eval price=mvfilter(mvindex(split(price,"|"),0)<mvindex(split(price,"|"),1))
| eval price=mvmap(price,mvindex(split(price,"|"),0))

Alternatively, you could do the comparison before the stats

| eventstats values(past_avg) as past_avg by id
| where price < past_avg
| stats values(*) as * by id
Get Updates on the Splunk Community!

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...

Reminder! Splunk Love Promo: $25 Visa Gift Card for Your Honest SOAR Review With ...

We recently launched our first Splunk Love Special, and it's gone phenomenally well, so we're doing it again, ...