<?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 Sort by alternative column in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651814#M53453</link>
    <description>&lt;P&gt;I have the following query displaying as a table in a classic dashboard:&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;| makeresults format=json data="[{\"item\":\"disk1\", \"size\":2147483648, \"size_pretty\":\"2 GB\"}, {\"item\":\"disk2\", \"size\":1099511627776, \"size_pretty\":\"1 TB\"}]"
| table item size size_pretty&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now when you sort by "size" the table works as expected (2GB is smaller than 1TB).&lt;/P&gt;&lt;P&gt;When you sort by "size_pretty" though, it of course will think that "1 TB" is first in order, followed by "2 GB" (lexicographic sort order).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like however (purely about user experience) is to&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Hide the "size" column as it will be pretty horrible to read&lt;/P&gt;&lt;P&gt;2) When the user clicks the "size_pretty"&amp;nbsp; column to sort the table, I want it to &lt;EM&gt;actually&lt;/EM&gt; sort by "size" (up or down) - Even though that column is not visible to the user, meaning the output (sorted smallest to largest) would look like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;item&lt;/TD&gt;&lt;TD width="50%"&gt;size_pretty&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;disk 1&lt;/TD&gt;&lt;TD width="50%"&gt;2 GB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;disk 2&lt;/TD&gt;&lt;TD width="50%"&gt;1 TB&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to achieve this? Note that I am on Splunk Cloud, so I do not have access to the file system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(if it can be done on a dynamic dashboard instead, i'd consider that)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bonus points if I can also apply column formatting with a colour scale as you would on a normal table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jul 2023 00:20:48 GMT</pubDate>
    <dc:creator>lindonmorris</dc:creator>
    <dc:date>2023-07-25T00:20:48Z</dc:date>
    <item>
      <title>Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651814#M53453</link>
      <description>&lt;P&gt;I have the following query displaying as a table in a classic dashboard:&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;| makeresults format=json data="[{\"item\":\"disk1\", \"size\":2147483648, \"size_pretty\":\"2 GB\"}, {\"item\":\"disk2\", \"size\":1099511627776, \"size_pretty\":\"1 TB\"}]"
| table item size size_pretty&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now when you sort by "size" the table works as expected (2GB is smaller than 1TB).&lt;/P&gt;&lt;P&gt;When you sort by "size_pretty" though, it of course will think that "1 TB" is first in order, followed by "2 GB" (lexicographic sort order).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like however (purely about user experience) is to&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Hide the "size" column as it will be pretty horrible to read&lt;/P&gt;&lt;P&gt;2) When the user clicks the "size_pretty"&amp;nbsp; column to sort the table, I want it to &lt;EM&gt;actually&lt;/EM&gt; sort by "size" (up or down) - Even though that column is not visible to the user, meaning the output (sorted smallest to largest) would look like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;item&lt;/TD&gt;&lt;TD width="50%"&gt;size_pretty&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;disk 1&lt;/TD&gt;&lt;TD width="50%"&gt;2 GB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;disk 2&lt;/TD&gt;&lt;TD width="50%"&gt;1 TB&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to achieve this? Note that I am on Splunk Cloud, so I do not have access to the file system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(if it can be done on a dynamic dashboard instead, i'd consider that)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bonus points if I can also apply column formatting with a colour scale as you would on a normal table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 00:20:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651814#M53453</guid>
      <dc:creator>lindonmorris</dc:creator>
      <dc:date>2023-07-25T00:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651816#M53454</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/63061"&gt;@lindonmorris&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Have a look at this answer&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-do-I-hide-a-column-in-a-table/m-p/425273" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/How-do-I-hide-a-column-in-a-table/m-p/425273&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;In a dashboard table you can define which columns are visible.&amp;nbsp; &amp;nbsp;I don't think you can use colours if the scale is different, e.g. GB and TB&lt;BR /&gt;&lt;BR /&gt;Hope that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 02:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651816#M53454</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-07-25T02:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651818#M53456</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/158935"&gt;@yeahnah&lt;/a&gt;&amp;nbsp;, that lets me hide the column, but rather than being able to control the drilldown, i'd like to control the sort behaviour&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 02:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651818#M53456</guid>
      <dc:creator>lindonmorris</dc:creator>
      <dc:date>2023-07-25T02:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651821#M53457</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/63061"&gt;@lindonmorris&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Yeah, it would not meet your second requirement to sort on the size_pretty column, when clicked.&amp;nbsp; For that you need to look at javascript, which starts getting complicated.&amp;nbsp; Not recommended.&lt;BR /&gt;&lt;BR /&gt;The only other way is to use a consistent size scale.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=json data="[{\"item\":\"disk1\", \"size\":2147483648, \"size_pretty\":\"2 GB\"}, {\"item\":\"disk2\", \"size\":1099511627776, \"size_pretty\":\"1 TB\"}]"
| eval size_pretty_gb=round(size/1024/1024/1024, 2)
| table item size_pretty_gb&lt;/LI-CODE&gt;&lt;P&gt;You could then define colour scales too.&lt;BR /&gt;&lt;BR /&gt;Hope that helps&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 02:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651821#M53457</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-07-25T02:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651822#M53458</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/158935"&gt;@yeahnah&lt;/a&gt;&amp;nbsp;, while my example would kinda work in that case, the numbers will be significantly different (varying from Bytes to Petabytes) so the dynamic unit is a necessity for readability.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 03:01:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651822#M53458</guid>
      <dc:creator>lindonmorris</dc:creator>
      <dc:date>2023-07-25T03:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651827#M53459</link>
      <description>&lt;P&gt;I'm not sure if it's possible to sort by a different column. However...there &lt;STRONG&gt;is&lt;/STRONG&gt; a way to display the "size" field in a pretty format, while retaining the underlying numerical data for sorting. This could work as long as you're not married to using the "size_pretty" from your JSON.&lt;/P&gt;&lt;P&gt;Here's an example search (with some additional data I added to test the sorting):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=json data="[{\"item\":\"disk1\", \"size\":2147483648, \"size_pretty\":\"2 GB\"}, {\"item\":\"disk2\", \"size\":1099511627776, \"size_pretty\":\"1 TB\"}, {\"item\":\"disk3\", \"size\":660, \"size_pretty\":\"660 B\"}, {\"item\":\"disk4\", \"size\":20147483648, \"size_pretty\":\"18 GB\"}, {\"item\":\"disk5\", \"size\":1047548, \"size_pretty\":\"1,023 KB\"}]" 

| fieldformat size=printf("%4u",round(size/pow(1024,if(size=0,0,floor(min(log(size,1024),10)))),2)).case(size=0 OR log(size,1024)&amp;lt;1," B", log(size,1024)&amp;lt;2," KB", log(size,1024)&amp;lt;3," MB", log(size,1024)&amp;lt;4," GB", log(size,1024)&amp;lt;5," TB", log(size,1024)&amp;lt;6," PB", log(size,1024)&amp;lt;7," EB", 1=1, " EB")

| table item size size_pretty&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This outputs a table like the following. It sorts the size column as expected, while retaining the pretty formatting:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cklunck_0-1690254668075.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/26438i7E09DDF96576B858/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cklunck_0-1690254668075.png" alt="cklunck_0-1690254668075.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can remove the "size_pretty" field from the | table command if you no longer wish to display it.&lt;/P&gt;&lt;P&gt;The color scale is up to you, but I think it might still be do-able since the underlying numeric data is still there.&lt;/P&gt;&lt;P&gt;This answer was inspired by the following post:&amp;nbsp; &lt;A href="https://community.splunk.com/t5/Dashboards-Visualizations/Is-there-a-smart-conversion-of-large-numbers-to-human-readable/m-p/629593" target="_blank" rel="noopener"&gt;Smart conversion of large numbers to human-readable format (Splunk Answers)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 03:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651827#M53459</guid>
      <dc:creator>cklunck</dc:creator>
      <dc:date>2023-07-25T03:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651829#M53460</link>
      <description>&lt;P&gt;OK,&amp;nbsp; I think I have a workable solution using the &lt;STRONG&gt;fieldformat&lt;/STRONG&gt; command.&amp;nbsp; Here's an example&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval size=split("2147483648:2GB,1099511627776:1TB,1125899906842624:1PB", ",")
| mvexpand size
| eval size_pretty=mvindex(split(size, ":"), 1), size=mvindex(split(size, ":"), 0)
| fieldformat size=size_pretty&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Basically, size shows the size_pretty value but the sort uses the size value to do the column sort order.&lt;BR /&gt;&lt;BR /&gt;Give it ago and see if it meets your requirements.&amp;nbsp; It will not help with colour scale mind you.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 03:35:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651829#M53460</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-07-25T03:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651832#M53461</link>
      <description>&lt;P&gt;Nice, I was working on a similar solution and had not seen your update yet.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 03:38:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651832#M53461</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-07-25T03:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by alternative column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651838#M53462</link>
      <description>&lt;P class="lia-align-left"&gt;That's perfect, thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/256817"&gt;@cklunck&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;&lt;BR /&gt;I had actually originally started using fieldformat, but for some reason switched to using eval (same/similar printf statements).&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;I didn't understand that it doesn't affect the underlying data, just the display of - So the sort works perfectly.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Many thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 04:57:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Sort-by-alternative-column/m-p/651838#M53462</guid>
      <dc:creator>lindonmorris</dc:creator>
      <dc:date>2023-07-25T04:57:14Z</dc:date>
    </item>
  </channel>
</rss>

