Hello experts,
I've been banging me head trying to figure out how to best approach this, keep in mind that I'm relatively new to Splunk. Monthly I go through and put together some sales metrics which shows the trends from the previous months. What I've been doing is manually changing the date in my searches and would like to have a more streamlined search that I don't have to update every month. I'm kinda stuck coming up with a way to set each month into their respective monthly group.
I have 4 main fields that I pull summary from:
acquired
sold
shipped
department
What I do is a stats count by the first three fields then group by department
First, I run some evals to set which month each event in those fields falls under, then I run stats count to count each one by month - sample search below.
initialSearch
|eval 1monthaq=if(like(acquired,"2016-11-%"), "Y", null())
|eval 2monthaq=if(like(acquired,"2016-10-%"), "Y", null())
|eval 1monthsold=if(like(sold,"2016-11-%"), "Y", null())
|eval 2monthsold=if(like(sold,"2016-10-%"), "Y", null())
|eval 1monthship=if(like(shipped,"2016-11-%"), "Y", null())
|eval 2monthship=if(like(shipped,"2016-10-%"), "Y", null())
|stats count each of the above by department
Since I always run this at the start or middle of the next month, is there an easy way for me to replace each of the 2016-11-% and 2016-10-% wildcards with something like strftime(now(),"%Y-%m") and then just subtract 1 for last month and 2 for 2 months ago from the %m in the date? Or this a better way to do this altogether?
Ultimately, what I'd like to do is get a count of each of the fields listed above (acquired, sold, shipped) by department and only include and group events that fall within each of their respective months.
sample data:
acquired=2016-09-01T01:22:56.000+0000
sold=2016-09-02T14:32:32.000+0000
shipped=2016-09-02T17:21:56.000+0000
department=mobile
acquired=2016-09-01T01:22:56.000+0000
sold=2016-09-03T14:32:32.000+0000
shipped=2016-09-03T17:21:56.000+0000
department=parts
acquired=2016-10-01T01:22:56.000+0000
sold=2016-10-02T14:32:32.000+0000
shipped=2016-10-02T17:21:56.000+0000
department=mobile
acquired=2016-10-03T01:22:56.000+0000
sold=2016-10-04T14:32:32.000+0000
shipped=2016-10-07T17:21:56.000+0000
department=mobile
Results I'm hoping for
Department 2016-10-shipped 2016-11-shipped 2016-10-sold 2016-11-sold
mobile 1 0 0 1
parts 1 0 1 1
Greatly appreciate the help.
... View more