<?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 How to use a variable to limit a sort list length? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339335#M100610</link>
    <description>&lt;P&gt;I want to find the highest ten results of a search and group the others up. I'm using the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo | stats sum(apple) as fruit by tree |sort limit =2 - fruit | append [search index=foo | stats count sum(apple) as fruit by tree | eval counter=(count-10) | sort limit =counter + fruit | stats sum(fruit) | fillnull value="other" tree]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried to use "tonumber" and "convert" function. It leads to the folowing error: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'sort' command: Invalid option value. Expecting a 'non-negative integer' for option 'limit'. Instead got 'counter'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How to get a list like this: &lt;BR /&gt;
tree1     |        8&lt;BR /&gt;
tree2       |            5&lt;BR /&gt;
other         |                    11&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2017 19:26:04 GMT</pubDate>
    <dc:creator>bebowi</dc:creator>
    <dc:date>2017-04-19T19:26:04Z</dc:date>
    <item>
      <title>How to use a variable to limit a sort list length?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339335#M100610</link>
      <description>&lt;P&gt;I want to find the highest ten results of a search and group the others up. I'm using the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo | stats sum(apple) as fruit by tree |sort limit =2 - fruit | append [search index=foo | stats count sum(apple) as fruit by tree | eval counter=(count-10) | sort limit =counter + fruit | stats sum(fruit) | fillnull value="other" tree]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried to use "tonumber" and "convert" function. It leads to the folowing error: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'sort' command: Invalid option value. Expecting a 'non-negative integer' for option 'limit'. Instead got 'counter'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How to get a list like this: &lt;BR /&gt;
tree1     |        8&lt;BR /&gt;
tree2       |            5&lt;BR /&gt;
other         |                    11&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2017 19:26:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339335#M100610</guid>
      <dc:creator>bebowi</dc:creator>
      <dc:date>2017-04-19T19:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable to limit a sort list length?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339336#M100611</link>
      <description>&lt;P&gt;I would try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo | stats sum(apple) as fruit by tree | sort 0 -fruit | streamstats count as rank | eval tree=if(rank=1 OR rank=2 , tree,"other" 
| stats sum(fruit) as fruit by tree
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2017 19:36:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339336#M100611</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-19T19:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable to limit a sort list length?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339337#M100612</link>
      <description>&lt;P&gt;It works, thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:10:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339337#M100612</guid>
      <dc:creator>bebowi</dc:creator>
      <dc:date>2017-04-20T15:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable to limit a sort list length?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339338#M100613</link>
      <description>&lt;P&gt;This answer may be fitted for the question. However it does not answer the question: how to use a variable to limit a list. I want to limit the number of bars in a barchart, depending on the days of the month. I can calculate the number of days, but when i use that variable to fill in the limit parameter, i got the same error as mentioned above. &lt;/P&gt;</description>
      <pubDate>Sun, 30 Sep 2018 13:37:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-a-variable-to-limit-a-sort-list-length/m-p/339338#M100613</guid>
      <dc:creator>jancjaarsma</dc:creator>
      <dc:date>2018-09-30T13:37:47Z</dc:date>
    </item>
  </channel>
</rss>

