Splunk Search

Adding computed column in Chart by date

hyp3rf0x
Engager

Hi, I have a search below to compare previous 2 days Splunk usage, but I need additional column that computes the difference between 2 dates. How can we achieve this?

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d
| eval b=round(b/1024/1024/1024,2)

| bin span=1d _time | eval date=strftime(_time,"%d_%b")
| chart sum(b) AS GB over host by date

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this query.  Usually, we use a simple eval to find the difference between two fields, but we can't do that here because the field names aren't known.

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d 
| eval b=round(b/1024/1024/1024+(random()%10),2) 
| bin span=1d _time 
| eval date=strftime(_time,"%d_%b") 
| chart sum(b) AS GB over host by date
| eval diff=0
| foreach *_* [ eval diff=if(diff==0,'<<FIELD>>',diff-'<<FIELD>>')]
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

hyp3rf0x
Engager

Wow.. this really helps and achieves what I need. Thank you @richgalloway , much appreciated.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this query.  Usually, we use a simple eval to find the difference between two fields, but we can't do that here because the field names aren't known.

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d 
| eval b=round(b/1024/1024/1024+(random()%10),2) 
| bin span=1d _time 
| eval date=strftime(_time,"%d_%b") 
| chart sum(b) AS GB over host by date
| eval diff=0
| foreach *_* [ eval diff=if(diff==0,'<<FIELD>>',diff-'<<FIELD>>')]
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk Classroom Chronicles: Training Tales and Testimonials (Episode 4)

Welcome back to Splunk Classroom Chronicles, our ongoing series where we shine a light on what really happens ...

From GPU to Application: Monitoring Cisco AI Infrastructure with Splunk Observability ...

AI workloads are different. They demand specialized infrastructure—powerful GPUs, enterprise-grade networking, ...

Application management with Targeted Application Install for Victoria Experience

  Experience a new era of flexibility in managing your Splunk Cloud Platform apps! With Targeted Application ...