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
Revered Legend

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
Revered Legend

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
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...