Splunk Search

How to dynamically select column in an XY series?

ajones
Explorer

Hello!

I am currently trying to dynamically select columns in my output that are generated by an xyseries.

I am comparing the difference in columns over a period of times, and I am running my y_field as the dates that dynamically change depending on the range selected. For example:

2023-06-04         2023-06-11

10                                     5

15                                  18

Without resulting to renaming the columns to something static like "Week 1" and "Week 2" and be able to still eval the two columns to get the mathematical difference. Sometime like:

eval DIFF=datecolumn[1]-datecolumn[0].

Thank you!

Labels (4)
0 Karma
1 Solution

danspav
SplunkTrust
SplunkTrust

Hi @ajones,

Here's a way you can get the difference - as long as your columns are in the right order (<week1>, <week2>)

The first section of the search is just to recreate your data.

| makeresults count=2
| streamstats count as id
| eval "2023-06-04"=if(id=1,10,15), "2023-06-11"=if(id=1,5,18)
| table 2023*
``` That was just to create dummy data ```

| foreach * [| eval total=if(isnull(total),0,total) | eval total=total+1| eval DIFF=if(total=1, -1* '<<FIELD>>', DIFF + '<<FIELD>>')] 
| fields - total

 
The second piece creates a "total" field, then we work out the difference for all columns.

We minus the first column, and add the second column - which gives us week2 - week1. 

This method needs the first week to be listed first and the second week second.  You can have the dates in any format, so "2023-06-04" will work just as well as "June 4, 2023".

danspav_2-1686962905951.png

 



Cheers,
Daniel

 

 

View solution in original post

0 Karma

danspav
SplunkTrust
SplunkTrust

Hi @ajones,

Here's a way you can get the difference - as long as your columns are in the right order (<week1>, <week2>)

The first section of the search is just to recreate your data.

| makeresults count=2
| streamstats count as id
| eval "2023-06-04"=if(id=1,10,15), "2023-06-11"=if(id=1,5,18)
| table 2023*
``` That was just to create dummy data ```

| foreach * [| eval total=if(isnull(total),0,total) | eval total=total+1| eval DIFF=if(total=1, -1* '<<FIELD>>', DIFF + '<<FIELD>>')] 
| fields - total

 
The second piece creates a "total" field, then we work out the difference for all columns.

We minus the first column, and add the second column - which gives us week2 - week1. 

This method needs the first week to be listed first and the second week second.  You can have the dates in any format, so "2023-06-04" will work just as well as "June 4, 2023".

danspav_2-1686962905951.png

 



Cheers,
Daniel

 

 

0 Karma

ajones
Explorer

Awesome, thank you so much! I had to make some slight modifications for it to not concatenate my other column, namely splitting and using mvindex to capture the right data. Overall works great!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...