Splunk Search

Overlaying a previous years data on chart

jackreeves
Explorer

I am displaying some data by Month for 2018/2019 (i.e. 01-2018, 02-2018) on a barchart.

Search Query:
( sourcetype=sourcetype1) OR (sourcetype=sourcetype2) OR (sourcetype=sourcetype3)
| chart sum(eval(if(sourcetype="sourcetype1",ICOS,NULL))) as Actuals sum(eval(if(sourcetype="sourcetype2",ICOS,NULL))) as Forecast sum(eval(if(sourcetype="sourcetype3",ICOS,NULL))) as Budget over "Month"

However I also want to be able to overlay 2017 data so that 2017-01 is shown above 2018-01 without adding to the x-axis.

Any ideas how I could do that?

0 Karma

grittonc
Contributor

If you are using Splunk 6.5 or higher, the timewrap function should be available and does exactly this.

https://answers.splunk.com/answers/468177/is-timewrap-an-official-spl-command-in-splunk-65.html

https://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Timewrap

You would first summarize your data using timechart, then use timewrap in the next pipe.

|timechart span=1m sum(my_field) | timewrap span=1y

The above should give you a year-over-year chart by month.

kmorris_splunk
Splunk Employee
Splunk Employee

Here is a technique from Exploring Splunk by David Carasso. I recommend downloading this since it has several good examples in it. This search shows how to compare last weeks results to this weeks results on the same chart, by labeling data from last week and this week, then adjusting _time so they line up for charting.

earliest=-2w@w latest=@w
 | eval marker = if (_time < relative_time(now(), “-1w@w”),
 “last week”, “this week”)
 | eval _time = if (marker==”last week”,
 _time + 7*24*60*60, _time)
 | timechart avg(bytes) by marker
0 Karma

jackreeves
Explorer

Thanks for the response. The pdf is very interesting.

I believe this would be quite messy when you try and apply across 12 months. Any alternatives?

0 Karma

jackreeves
Explorer

Added below to search and has worked 🙂
| appendcols
[ search index=finance sourcetype=hfm_actuals Country1="EMEIA" AND Organisation="DTS_DWS" "Financial Year ending"=2018
| eval _time=relative_time((_time),"+1year")
| chart sum(ICOS) as "FY18 Actuals" over Month]

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...