I report on a count of events by week number, it displays like this:
Week Number Count
----------- -----
01 15
02 35
03 35
...
I use strftime(_time, "%v") to get the week number. How can I also display the calendar month and day of the first day of each week in the report? Ideally, the report would look like this:
Week Number Week Begin Count
----------- ---- -----
01 12/31 15
02 01/07 35
03 01/14 35
...
try this
| eval Day1ofWeek = strftime(relative_time(_time,"@w0"),"%m/%d")
will be the Sunday. If you want the Monday, use this
| eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%m/%d")
try this
| eval Day1ofWeek = strftime(relative_time(_time,"@w0"),"%m/%d")
will be the Sunday. If you want the Monday, use this
| eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%m/%d")
Exactly what I was looking for, thanks!
Does this work in Splunk 6.1.3? I cannot get the additional column to display when I append the piped statement to my search strings.
It does work on 6.1.3. Above statement requires field _time to be available before this command. What is your current query?
I have a set of data that I am averaging weekly using eval week=strftime(_time,"%Y-%U"). I then display this using chart values(foo) by week, bar.
However, I'd like to replace the week column with the date of the Monday of that week when it is displayed in the table. I would still like the data to be sorted by week still, but I do not want the week number to be displayed, only for that Monday of that week to be displayed. Thanks.
I wanted to generated a the Day1ofWeek column and appendcols to my search query but just generating a Day1ofWeek column with my query doesn't work.
What do you mean by "requires field _time to be available before this command"? Does that mean that I cannot use _time in my eval week statement?
The answer by Lisa uses field _time (epoch format) to generate the Day1ofWeek, which is not available after your chart command, you can't use it directly. What I would suggest is to use something like this
your base search | eval week=relative_time(_time,"@w1")| chart values(foo) by week,bar| eval week=strftime(week,"%Y-%m-%d %a")
It will be sort ascending order of the date/week.
That worked! Thanks so much especially with the prompt responses.