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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...