Splunk Search

How can I count by date, field, and range?

tkwaller_2
Communicator

Hello

I have some steps in a table that have a due date and SLA tied to them. Im trying to sum number of SLA days by date range.

Heres an example table:

Name      SLA        Due Date
Sample 1    5  2018-05-03 22:59:17.246000
Sample 2    10   2018-04-27 22:59:17.246000
Sample 3    5  2018-03-20 22:59:17.246000
Sample 4    5  2018-03-13 22:59:17.246000
Sample 5    2  2018-02-27 22:59:17.246000

I'm trying to total SLA by Date Range -
"Sum of SLA days for Next 30 days"

"Sum of SLA days for 31-60 days"

"Sum of SLA days for 61-90 days"

"Sum of SLA days for 90+ days"

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

your current search giving table with fields Name SLA "Due Date"
| eval DateRange=round((strptime('Due Date',"%Y-%m-%d %H:%M:%S.%6N")-now())/86400)
| eval DateRange=case(DateRange<=30,"Next 30 days",DateRange<=60,"31-60 days", DateRange<=90,"61-90 days",true(),"90+ days)
| stats sum(SLA) as "total SLA" by DateRange
| eval DateRange="Sum of SLA days for ".DateRange

View solution in original post

somesoni2
Revered Legend

Give this a try

your current search giving table with fields Name SLA "Due Date"
| eval DateRange=round((strptime('Due Date',"%Y-%m-%d %H:%M:%S.%6N")-now())/86400)
| eval DateRange=case(DateRange<=30,"Next 30 days",DateRange<=60,"31-60 days", DateRange<=90,"61-90 days",true(),"90+ days)
| stats sum(SLA) as "total SLA" by DateRange
| eval DateRange="Sum of SLA days for ".DateRange
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...