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
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...