Splunk Search

How can I calculate a percentage over time?

acabrera1
Explorer

I have the following search command defined by a custom time range (last 2 weeks):

index=mlr3_google sourcetype=mlr3_google_ext | bucket span=1w _time | eval Date=strftime(_time,"%m-%d-%y") | chart sum(uniqueVisitors) over sourcetype by Date 

I want to calculate the percentage change for this week from last week.
How do I calculate that?

Tags (2)

ziegfried
Influencer

You probably want to do smth like this:

index=mlr3_google sourcetype=mlr3_google_ext | eval Date=if(_time>relative_time(now(),"-1w"),"this_week","last_week") | chart sum(uniqueVisitors) as count over sourcetype by Date | eval change_pct=if(last_week==0,"-",if((this_week-last_week)>0,"+","")+tostring(round((this_week-last_week)/last_week*100,1))+"%") | table sourcetype last_week this_week change_pct | rename last_week as "Last week" this_week as "This week" change_pct as "Change in %"

acabrera1
Explorer

Specifying the time range actually solves the problem! Thanks so much for your help!!

0 Karma

acabrera1
Explorer

Thank you for the response however I noticed that the value for 'last week' is summing all previous weeks instead of taking the value of only 'last week'. How can I modify your command to only calculate only 7 days last week?

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...