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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...