<?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 Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100 in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007645#M37634</link>
    <description>&lt;P&gt;I'm running an app built in WebApp Builder to display archaeological reports. I've built a query to allow searching by date, author etc as well as the map search. The query is supposed to sort first by date (formatted as a number it's only the year that matters) and then by report number (also formatted as a number). However, when running the query it sorts the output by date, but then seems to count the Number as text because it counts 1,2,3,4,5,6,10,100,101-109,11,110-119,12 etc. Has anyone come across such an issue before, and have you any idea how to rectify it?&lt;/P&gt;&lt;P&gt;I could reformat the field as text, adding leading zeros, but that seems counter intuitive, when I have a numeric field&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 08 Dec 2020 11:37:17 GMT</pubDate>
    <dc:creator>SimonCrutchley</dc:creator>
    <dc:date>2020-12-08T11:37:17Z</dc:date>
    <item>
      <title>Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007645#M37634</link>
      <description>&lt;P&gt;I'm running an app built in WebApp Builder to display archaeological reports. I've built a query to allow searching by date, author etc as well as the map search. The query is supposed to sort first by date (formatted as a number it's only the year that matters) and then by report number (also formatted as a number). However, when running the query it sorts the output by date, but then seems to count the Number as text because it counts 1,2,3,4,5,6,10,100,101-109,11,110-119,12 etc. Has anyone come across such an issue before, and have you any idea how to rectify it?&lt;/P&gt;&lt;P&gt;I could reformat the field as text, adding leading zeros, but that seems counter intuitive, when I have a numeric field&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 11:37:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007645#M37634</guid>
      <dc:creator>SimonCrutchley</dc:creator>
      <dc:date>2020-12-08T11:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007652#M37636</link>
      <description>&lt;P&gt;You want what is called a "natural sort"&lt;/P&gt;&lt;P&gt;I can only demonstrate using python...&lt;/P&gt;&lt;LI-CODE lang="python"&gt; a = ['1', '21', '3', 'r4', 'r41', '7', '71', 'r711', '10', 'r100']
b = sorted(a)
print("input - \n{}".format(a))
print("text sort - \n{}".format(b))
vals = natsort(a)
print("natural sort - \n{}".format(vals))
input - 
['1', '21', '3', 'r4', 'r41', '7', '71', 'r711', '10', 'r100']
text sort - 
['1', '10', '21', '3', '7', '71', 'r100', 'r4', 'r41', 'r711']
natural sort - 
['1', '3', '7', '10', '21', '71', 'r4', 'r41', 'r100', 'r711']&lt;/LI-CODE&gt;&lt;P&gt;The process and code&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import re
def natsort(lst):
    """natural sort"""
    import re
    convert = lambda text: int(text) if text.isdigit() else text
    a_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    return sorted(lst, key=a_key)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Dec 2020 11:55:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007652#M37636</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-12-08T11:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007655#M37637</link>
      <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;Thanks for that, but I still don't understand why it isn't just sorting 'naturally' anyway. The field is numeric, so surely it should sort 1,2,3,4,5,6,7,8,9,10,11,12 etc.&lt;/P&gt;&lt;P&gt;I'm afraid I don't understand the code etc.&lt;/P&gt;&lt;P&gt;Sorry&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 12:17:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007655#M37637</guid>
      <dc:creator>SimonCrutchley</dc:creator>
      <dc:date>2020-12-08T12:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007657#M37638</link>
      <description>&lt;P&gt;It would sort in numeric order if it were numeric.&amp;nbsp; If it is sorted as you show, it is text and to get it to sort as a number, it has to be converted from text to number.&amp;nbsp; A number can look like a number, but you may not see what makes it appear as text.&lt;/P&gt;&lt;P&gt;The code sample is what could be used for field calculations in tables in ArcGIS Pro, for instance&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 12:25:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007657#M37638</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-12-08T12:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007659#M37639</link>
      <description>&lt;P&gt;But it is numeric, at least according to the field data (see attached). That's what I don't understand.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 12:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007659#M37639</guid>
      <dc:creator>SimonCrutchley</dc:creator>
      <dc:date>2020-12-08T12:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007691#M37642</link>
      <description>&lt;P&gt;apparently the combination of date formatted as a number and a number doesn't yield a sortable number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 14:22:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007691#M37642</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-12-08T14:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Results in query not sorting properly. Sorting by numeric field, but reading like text and jumping from 10 to 100</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007695#M37643</link>
      <description>&lt;P&gt;In the query, the date is all the same in all the examples I've tried; it's the No field, which is just a number, that fails to sort.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 14:25:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/results-in-query-not-sorting-properly-sorting-by/m-p/1007695#M37643</guid>
      <dc:creator>SimonCrutchley</dc:creator>
      <dc:date>2020-12-08T14:25:26Z</dc:date>
    </item>
  </channel>
</rss>

