Dashboards & Visualizations

how to group events per weeknumber ?

yannK
Splunk Employee
Splunk Employee

I tried different methods, but couldn't group events per week.
with span=1week, it seems to do a rotating 7 days.

Any way to define the weeknumber in splunk ?

Tags (2)
1 Solution

yannK
Splunk Employee
Splunk Employee

I found a workaround for searches and dashboard is to manually extract them after the search using a strftime

… | eval weeknumber=strftime(_time,"%U") | stats count by weeknumber

To avoid confusions between years, I like to use the year, that help to sort them in chronological order.

… | eval dateyearweek=strftime(_time,"%Y-%U")| stats count by dateyearweek

Depending of your country, you have 2 variations :

  • %U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
  • %V is replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1.

View solution in original post

olex_k7
Engager

It may have been "strftime(_time,"%U")" as yannK said.
But in the current Splunk version is the week number defined by "%V"

So, the code snippet should be:

| eval dateyearweek=strftime(_time,"%Y-%V")| stats count by dateyearweek

See Docs for more info. Best Regards!

0 Karma

yannK
Splunk Employee
Splunk Employee

I found a workaround for searches and dashboard is to manually extract them after the search using a strftime

… | eval weeknumber=strftime(_time,"%U") | stats count by weeknumber

To avoid confusions between years, I like to use the year, that help to sort them in chronological order.

… | eval dateyearweek=strftime(_time,"%Y-%U")| stats count by dateyearweek

Depending of your country, you have 2 variations :

  • %U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
  • %V is replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1.
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 ...