Splunk Search

voulme data comparison

selvam_sekar
Path Finder

Hi,

I have below SPL, which return todays count vs yesterday count and difference between them. I want to see, if i run this search on monday, then the "yesterday" should be last Friday data instead of weekend. could you pls help ?

SPL:

base search  earliest=@d latest=now
| append
[ base search earliest=-1d@d latest=-1d ]
| eval Day=if(_time<relative_time(now(),"@d"),"Yesterday","Today")
| chart count by Name, Day
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Today Yesterday percentage_variance
Labels (3)
Tags (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@selvam_sekar - You can filter the data beforehand and then do what you would do otherwise.

Something like this with streamstats command:

basesearch  earliest=-4d@d latest=now
| bin span=1d _time
| stats count by Name, _time, date_wday
| search NOT date_wday="saturday" OR date_wday="sunday"
| streamstats current=f window=1 last(count) as Yesterday by Name
| rename count as Today
| stats first(*) as * by Name
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Today Yesterday percentage_variance

 

I hope this helps!!! Kindly upvote if it does!!!

 

0 Karma

selvam_sekar
Path Finder

@VatsalJagani  Many thanks for the response.

The SPL/query seems to be picking up the data slightly different. What i'm getting is today colunm volume is friday data and yesterday count also coming from friday data.

can you help pls?

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@selvam_sekar - Here is the query with slight modification. Though in my case even with original query I'm getting the right count for today and yesterday.

basesearch  earliest=-4d@d latest=now
| bin span=1d _time
| search NOT date_wday="saturday" OR date_wday="sunday"
| stats count by Name, _time
| streamstats current=f window=1 last(count) as Yesterday by Name
| rename count as Today
| where strftime(_time, "%F")==strftime(now(), "%F")
| stats first(*) as * by Name
| eval percentage_variance=abs(round(((Yesterday-Today)/Yesterday)*100,2))
| table Name Today Yesterday percentage_variance

 

I hope this helps!!! Kindly upvote & accept the answer if it does!!!

 

0 Karma
Get Updates on the Splunk Community!

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

&#x1f5e3; You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...

What's New in Splunk Observability - October 2025

What’s New?    We’re excited to announce the latest enhancements to Splunk Observability Cloud and share ...