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
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...