Splunk Search

How to sum a field grouped by months using a date field

handygecko
Explorer

I'm new to splunk and I'm still struggling to grasp how it works. I uploaded data from a simple csv file. Data is as follows:

Column A       Column B
1/1/2012         9
2/1/2012         5
3/1/2012         17
1/17/2012       11

I would like to sum column B by Month as follows:

Jan                20
Feb               5
Mar              17

Ultimately, I'm looking to create a bar chart displaying this data by year. Any help is greatly appreciated.

Tags (2)
0 Karma
1 Solution

Ayn
Legend

Assuming you have your timestamps working correctly:

... | timechart span=1mon sum(B)

View solution in original post

0 Karma

Ayn
Legend

Assuming you have your timestamps working correctly:

... | timechart span=1mon sum(B)

0 Karma

Ayn
Legend

Splunk shold do this by default. It'll use the first date it encounters in each event.

0 Karma

handygecko
Explorer

You got me going on the right track. Splunk was failing to parse timestamps. I managed to index several files properly, however, a couple files require a more complex regular expression for the preface pattern. The events are structured as follows:

"Justin Lang:2465-1-Lang","164","10/4/2012","10/25/2012",,4345.00,""

Do you happen to know how to write a regular expression that would allow splunk to parse the first date in the event: "10/4/2012"? I do not know regex very well. I tried "",""," Thanks for your help!

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...