Splunk Search

How to sort dynamic column names?

avitallange
Explorer

Hi,

I have 2 columns: Name and Value.
My column names are dynamically changed.
How can I sort the column Names?
Please note I cannot use fields command to set the order since I don't know the column names in advance.

This is an example for my search:

... | chart  avg(Value) AS Value by Name | sort  -Value | head 10 | eval N=Name | eval Name ="" | xyseries Name N Value

I am replacing the X and Y with xyseries, so I get dynamic column names.
Is it possible to sort them?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this workaround (it will add a rank to in the values of Name but will do the sorting)

... | chart avg(Value) AS Value by Name| sort - Value| head 10 | eval rank=1 | accum rank | eval rank=rank-1| eval Name=rank." ".Name | eval rank="" | xyseries rank Name Value | table rank *

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try this workaround (it will add a rank to in the values of Name but will do the sorting)

... | chart avg(Value) AS Value by Name| sort - Value| head 10 | eval rank=1 | accum rank | eval rank=rank-1| eval Name=rank." ".Name | eval rank="" | xyseries rank Name Value | table rank *

avitallange
Explorer

This made the sort indeed.
Thanks you!!!

0 Karma

vasanthmss
Motivator

Try this

... | chart avg(Value) AS Value by Name | sort -Value | head 10 | eval N=Name | eval Name ="" | xyseries Name N Value | table *
V

avitallange
Explorer

Thanks for your response but it didn't help.
I am actually want to get my columns in the chart sorted.
I.E. the most highest column will be the most left column and the most lowest columns will be the most right column.

I am unable to do this because I used xyseries that replaced my axis and now each Value is a column and I cannot sort by this Value. Sort is working on column and now I need to sort by row.
Is this possible?

0 Karma

avadhutha
Explorer
 
@avitallangedo you have any solution to sort from higher to lower for a dynamic columns in a chart?
0 Karma

DanielPi
Moderator
Moderator

Hi @avadhutha -

I’m a Community Moderator in the Splunk Community. 
This question was posted 10 years ago, so it might not get the attention you need for your question to be answered. We recommend that you post a new question so that your issue can get the  visibility it deserves. To increase your chances of getting help from the community, follow these guidelines in the Splunk Answers User Manual when creating your post.

Thank you! 

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...