Splunk Search

How do I make a search that compares weekly values and shows the percentage difference between fields?

becksyboy
Communicator

Hi,

I would like to compare 1 week of tabled data to the previous weeks and calculate the percentage difference for each field value for field note_label

Initial search:

 search... | stats count by note_label

 note_label      count
 abc                   10
 abcd           20
 abcde          30

I would like to show the data as:

note_label      count (week1)  count(week2)   %Change
 abc                   10          20                   100%
 abcd                 20          5                     -75%
 abcde          40             60                    50%

I may be following the wrong route as i tried this but had no luck, and may need to use a different method? This search only give me the "note_label" field value names, but not the values.

 earliest=-1w latest=now my_search | stats earliest(note_label) as e_status_label latest(note_label) as l_note_label  | eval 1w=(l_note_label-e_note_label)/e_note_label*100
 | appendcols [ search earliest=-2w latest=now my_search | stats earliest(note_label) as e_note_label latest(note_label) as l_note_label  | eval 2w=(l_note_label-e_note_label)/e_note_label*100 ]
 | fields note_label 1w 2w

thanks

0 Karma
1 Solution

becksyboy
Communicator

I managed to figure it out in the end. I stuck with appendcols and changed my search with eval to calculate the percentage differences;

earliest=-1w latest=now MYSEARCH | rename count AS count_this_week status_label AS Supression_status
| appendcols
[ search earliest=-2w latest=-1w
MYSEARCH | rename count AS count_last_week status_label AS Supression_status] | eval change= ((count_this_week - count_last_week)/count_this_week)*100 | eval change=round(change,2) | eval change= change+ " %"|fields Supression_status, count_this_week, count_last_week, change

View solution in original post

0 Karma

becksyboy
Communicator

I managed to figure it out in the end. I stuck with appendcols and changed my search with eval to calculate the percentage differences;

earliest=-1w latest=now MYSEARCH | rename count AS count_this_week status_label AS Supression_status
| appendcols
[ search earliest=-2w latest=-1w
MYSEARCH | rename count AS count_last_week status_label AS Supression_status] | eval change= ((count_this_week - count_last_week)/count_this_week)*100 | eval change=round(change,2) | eval change= change+ " %"|fields Supression_status, count_this_week, count_last_week, change

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...