<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sorting based on column values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600539#M209057</link>
    <description>&lt;P&gt;See if something like this would work for you (everything before the chart command is to generate sample data, change it with your search)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval temp="{\"data\": { \"a\": 100, \"b\": 200 }}#{\"data\": { \"a\": 50, \"c\": 75 }}" | makemv delim="#" temp | mvexpand temp | rename temp as _raw | extract 
| chart sum(data.*) as * 
| eval temp=1 | untable temp key value | sort 0 -value | head 10 | streamstats count | eval key=substr("00000000000".tostring(count),-3)."-".key | xyseries temp key value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jun 2022 20:16:25 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2022-06-03T20:16:25Z</dc:date>
    <item>
      <title>How to sort based on column values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600536#M209055</link>
      <description>&lt;P&gt;I have some data that's coming in as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"data": { "a": 100, "b": 200 }
"data": { "a": 50, "c": 75 }
...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to aggregate the values so I end up with a table of the sum of values by key:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search&amp;gt; | chart sum(data.*) as *&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;This gives me the table:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;a&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;b&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;150&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;200&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;75&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I want to sort the columns by value so that it is in the order b, a, c. It looks like the "sort" keyword sorts by rows and not columns. How would I do this?&lt;/P&gt;
&lt;P&gt;Note this is an extremely simplified example and the actual data will have tons of keys which are arbitrary uuids and there will be a lot of rows to sum. I need to aggregate and then sort by value to have the highest on the left-hand-side. I would also like to only keep the first n columns. It looks like "head" also works by rows and not columns.&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 03:28:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600536#M209055</guid>
      <dc:creator>mldavis195</dc:creator>
      <dc:date>2022-06-06T03:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting based on column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600539#M209057</link>
      <description>&lt;P&gt;See if something like this would work for you (everything before the chart command is to generate sample data, change it with your search)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval temp="{\"data\": { \"a\": 100, \"b\": 200 }}#{\"data\": { \"a\": 50, \"c\": 75 }}" | makemv delim="#" temp | mvexpand temp | rename temp as _raw | extract 
| chart sum(data.*) as * 
| eval temp=1 | untable temp key value | sort 0 -value | head 10 | streamstats count | eval key=substr("00000000000".tostring(count),-3)."-".key | xyseries temp key value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 20:16:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600539#M209057</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2022-06-03T20:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting based on column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600541#M209059</link>
      <description>&lt;P&gt;This also worked for me (I changed the field names slightly because I didn't want to deal with json &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but the same idea applies )&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;|makeresults | eval data_a=100, data_b=200&lt;BR /&gt;|append [|makeresults | eval data_a=50, data_c=75]&lt;BR /&gt;| chart sum(data_*) as *&lt;BR /&gt;| eval blah="blah"&lt;BR /&gt;| untable blah key value&lt;BR /&gt;| sort 0 -value&lt;BR /&gt;| head 10&lt;BR /&gt;| transpose 0 header_field=key&lt;BR /&gt;| search column=value&lt;BR /&gt;| fields - blah column&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jun 2022 20:29:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600541#M209059</guid>
      <dc:creator>rymundo_splunk</dc:creator>
      <dc:date>2022-06-03T20:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting based on column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600690#M209095</link>
      <description>&lt;P&gt;This worked like a charm. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 13:37:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-based-on-column-values/m-p/600690#M209095</guid>
      <dc:creator>mldavis195</dc:creator>
      <dc:date>2022-06-06T13:37:21Z</dc:date>
    </item>
  </channel>
</rss>

