<?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: Can if function be used with sort? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416312#M119835</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;| eval sort_field = if(count==disctinct_count, distinct_count, count)
| sort -sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can try this.&lt;BR /&gt;
Hope this helps, Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 16 Oct 2019 17:34:39 GMT</pubDate>
    <dc:creator>sandeepmakkena</dc:creator>
    <dc:date>2019-10-16T17:34:39Z</dc:date>
    <item>
      <title>Can if function be used with sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416310#M119833</link>
      <description>&lt;P&gt;I am working on a dashboard that has a radio button that can change a search between the two of the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by fieldA 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats dc(fieldA)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;At the end of this search I would like to have a sort based on whether or not count or distinct count is being used. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sort - count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sort - distinct_count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this something that I can accomplish using the if function? The following is a non functional example of what I would like to do something like. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if(count==disctinct_count, sort - distinct_count, sort - count)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you for any insight you might have.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 14:09:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416310#M119833</guid>
      <dc:creator>kamryn</dc:creator>
      <dc:date>2019-07-29T14:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can if function be used with sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416311#M119834</link>
      <description>&lt;P&gt;No, there is no way to do this that I'm familiar with.&lt;/P&gt;

&lt;P&gt;Could you just try changing one of the stats functions to rename the field? E.g. change:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| stats dc(fieldA)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;to&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| stats dc(fieldA) as count&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;then, keep the normal sort&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| sort - count&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 14:43:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416311#M119834</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-07-29T14:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Can if function be used with sort?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416312#M119835</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| eval sort_field = if(count==disctinct_count, distinct_count, count)
| sort -sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can try this.&lt;BR /&gt;
Hope this helps, Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 17:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-if-function-be-used-with-sort/m-p/416312#M119835</guid>
      <dc:creator>sandeepmakkena</dc:creator>
      <dc:date>2019-10-16T17:34:39Z</dc:date>
    </item>
  </channel>
</rss>

