Splunk Search

How to dynamically subtract two last column values?

chrisboy68
Contributor

Hi, have  SPL that generates months of data. I want subtract just the last two columns. The fields will change month to month, so I can't hard code.

Given the below sample, how can I get lastMonthDiff without hardcoding the field values? Thank you! Chris

 

 

 

| makeresults 
| eval "2202-01"=1 
| eval "2202-02"=2 
| eval "2202-03"=5 
| eval "2202-04"=4 
| append 
    [| makeresults 
    | eval "2202-01"=4 
    | eval "2202-02"=5 
    | eval "2202-03"=7 
    | eval "2202-04"=3
        ] 
| append 
    [| makeresults 
    | eval "2202-01"=5 
    | eval "2202-02"=2 
    | eval "2202-03"=7 
    | eval "2202-04"=9
        ] 
| fields - _time |foreach *  [eval lastMonthDiff = '2202-03' - '2202-04'] 

 

 

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| foreach *
    [| eval diff=if(isnull(previous),null(),previous-'<<FIELD>>')
    | eval previous='<<FIELD>>']

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| foreach *
    [| eval diff=if(isnull(previous),null(),previous-'<<FIELD>>')
    | eval previous='<<FIELD>>']

chrisboy68
Contributor

Awesome, thank you!

0 Karma
Get Updates on the Splunk Community!

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...