Splunk Search

How can I add a column at the end that shows the difference between the two weeks?

JoeHubner
Explorer

I would like to add a column to a chart that is the difference of the two columns before it in an application where I am showing the Cost for each employee for the last 2 weeks.   Using the search:

index=SampleData 

| where _time>relative_time(now(),"-2w@w")

| convert timeformat="%m-%d-%Y" ctime(_time)

| chart sum(Cost) over Employee by _time

The above produces a chart that looks like the following

Employee        05-08-2022     05-15-2022

Employee1      100.00             150.00
Employee2      200.00             175.00

How can I add a column at the end that shows the difference between the two weeks?

Labels (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

index=SampleData 
| where _time>relative_time(now(),"-2w@w")
| convert timeformat="%m-%d-%Y" ctime(_time)
| chart sum(Cost) over Employee by _time
| eval diff=-1
| foreach 0* 1* [| eval diff=if(diff=-1,'<<FIELD>>','<<FIELD>>'-diff)]

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try

index=SampleData 
| where _time>relative_time(now(),"-2w@w")
| convert timeformat="%m-%d-%Y" ctime(_time)
| chart sum(Cost) over Employee by _time
| eval diff=-1
| foreach 0* 1* [| eval diff=if(diff=-1,'<<FIELD>>','<<FIELD>>'-diff)]
0 Karma

JoeHubner
Explorer

Worked perfect, thanks.

Tags (1)
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 ...