Splunk Search
Highlighted

How to sort dynamic column names?

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
Highlighted

Re: How to sort dynamic column names?

Motivator

Try this

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

Re: How to sort dynamic column names?

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
Highlighted

Re: How to sort dynamic column names?

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

Highlighted

Re: How to sort dynamic column names?

Explorer

This made the sort indeed.
Thanks you!!!

0 Karma