Splunk Search

how can I find the average of a field in 2 different timeline

SridharS
Path Finder

Hi, I need to find the average value of a field at 2 different time. One is 4 days before and other is 1 day before. I used the below query but am not able to fetch the "1 day" before data. Any advice is appreciated!!

search........|stats avg(cpu_usage) as average| untable _time Metrics Value |eval Date=if(_time=relative_time(-1d,"-4d"), "Latest","Earliest") |chart first(Value) over Metrics by Date limit=0

Tags (2)
0 Karma

somesoni2
Revered Legend

After your stats there is no field called _time hence remaining search doesn't give the results you want. Try something like this

your base search | bucket span=1d _time | stats avg(cpu_usage) as average by _time | eval Date=if(_time=relative_time(now(),"-1d@d"), "Latest","Earliest") | eval Metrics="Average CPU Usage"  |chart first(Value) over Metrics by Date limit=0
0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...