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!

Splunkers, Pack Your Bags: Why Cisco Live EMEA is Your Next Big Destination

The Power of Two: Splunk &#43; Cisco at "Ludicrous Scale"   You know Splunk. You know Cisco. But have you seen ...

Data Management Digest – January 2026

Welcome to the January 2026 edition of Data Management Digest! Welcome to the January 2026 edition of Data ...

Splunk SOAR Now Available on Google Cloud Platform

We’re excited to announce that Splunk SOAR is now natively available as a SaaS solution on Google Cloud ...