Splunk Search

To compare the value of particular day with the same day of the last week and last to last week.

Real_captain
Path Finder

Hi 
Can someone please tell me how we can compare the value of a particular day with the value of the same day of last week and create a new field as deviation. 

Example : 
Below command generates the output as below : 

| stats sum(Number_Events) as TOTAL by FIeld1 FIeld2  FIeld3 Day  Time Week_of_year Total

Real_captain_3-1728394005350.png


We need the output like below : 

1. In tabular form : Is it possible to have an output like below : 

Real_captain_4-1728394466105.png

2. If point 1 is possible to be created , then Is it possible to have a time-chart with 3 lines over the 24 hours of the day . Example of data for 3 hours is attached 
1 line corresponds to Week of year -2 (39)
2nd line corresponds to Week of year -1 (40)
3rd line corresponds to Week of year (41)

Real_captain_5-1728394605105.png

 



Thanks in advance to help me out. 

 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as Total by field1 field2 field3 Day Time Week
| eval Week_{Week} = Total
| stats values(Week_*) as Week_* by field1 field2 field3 Day Time
| fillnull value=0
| eval Deviation=2*Week_41/(Week_39+Week_40)
0 Karma

Real_captain
Path Finder

HI @ITWhisperer 
Thanks for the response. 

But instead of hard-coading the week number to generate the deviation 

 | eval Deviation=2*Week_41/(Week_39+Week_40)  the week 

Can we dynamically give the dynamic value of the week as below : 

 | eval Deviation=2*Week_{current_week}/(Week_{current_week - 1} +Week_{current_week - 2})


Thanks in advance. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Just re-evaluate Week after the stats command to be current week, current week -1 and current week -2 as appropriate

0 Karma

Real_captain
Path Finder

Hi @ITWhisperer 
Can you please let me how can I correct the below stats command to re-evaluate Week after the stats command to be current week, current week -1 and current week -2. 

| stats count as Total by field1 field2 field3 Day Time Week
| eval Week_{Week} = Total
| stats values(Week_*) as Week_* by field1 field2 field3 Day Time
| fillnull value=0
| eval Deviation=2*Week_41/(Week_39+Week_40)

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as Total by field1 field2 field3 Day Time Week
| eventstats max(Week) as ThisWeek
| eval Week=if(Week=ThisWeek,"CurrentWeek","CurrentWeek".(Week-ThisWeek))
| eval {Week} = Total
| stats values(Current*) as Current* by field1 field2 field3 Day Time
| fillnull value=0
| eval Deviation=2*CurrentWeek/('CurrentWeek-2'+'CurrentWeek-1')
0 Karma

Real_captain
Path Finder

@ITWhisperer  : Thanks It worked. You are best 🙂

Just a small correction related to the order of columns.
Is it possible to have currentweek-4 column first, then currentweek-3 , then currentweek-2  , then currentweek-1 and , currentweek in the end before Deviation. 

 

Real_captain_1-1728466161262.png

 






0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Just append a table command listing the fields in the order you want them

0 Karma

Real_captain
Path Finder

Hi @ITWhisperer 
As CurrentWeek* is calculated dynamically , how can i put that field in the table command. 
If i use the below table command , it shows me the result in the same order. 
How can i reverse the order of the CurrentWeek columns ??? 

| table A B C DAY_OF_WEEK Start_Time CurrentWeek* Deviation

Real_captain_0-1728475312762.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Don't use wildcards or at least not for the -1 -2 -3 part - currently in your screenshot all the names are fixed

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...