[Solved] Sort text1 through text19 correctly

Discuss the spreadsheet application
Locked
procadman
Posts: 6
Joined: Sat Feb 10, 2018 7:16 pm

[Solved] Sort text1 through text19 correctly

Post by procadman »

I'm sure this has been covered but I could not find any record of it.

I often have records that have a column containing 1 thru 19.

Using this column as the first section of a sort returns 1, 10, 11, 12, etc.

How do I force it to read correctly? e.g.: 1, 2, 3, ...10, 11, 12...

Feel free to direct me to a post that already covers this.
Last edited by MrProgrammer on Mon Mar 03, 2025 6:45 pm, edited 3 times in total.
Reason: Tagged ✓ [Solved]; Use LibreOffice; Edit subject to show that text is being sorted, not numbers
OpenOffice 3.1 on Windows Vista
User avatar
robleyd
Moderator
Posts: 5504
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Sorting 1 thru 19 correctly

Post by robleyd »

Your "numbers" are text. Some related topics here:
viewtopic.php?t=45912
viewtopic.php?t=90617
viewtopic.php?t=83287
Slackware 15 (current) 64 bit
Apache OpenOffice 4.1.16
LibreOffice 26.2.3.2; SlackBuild for 26.2.3 by Eric Hameleers
---------------
I hate this damn computer, I wish that I could sell it.
It won't do what I want it to, Only what I tell it.
User avatar
Lupp
Volunteer
Posts: 3756
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Sorting 1 thru 19 correctly

Post by Lupp »

LibreOffice has a sorting option "Enable natural sort" which would produce the results you (OQer) expected in the given case.
However, the variants of texts containing numerical parts are many, and the feature is of limited vaue.
Last edited by Lupp on Thu Feb 20, 2025 3:25 pm, edited 3 times in total.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
procadman
Posts: 6
Joined: Sat Feb 10, 2018 7:16 pm

Re: Sorting 1 thru 19 correctly

Post by procadman »

re robleyd suggestions
I had already seen the 1st reference but I don't think it applies here.

Here is a sample of the ~350 records output:

exec3b1
exec3b10
exec3b11
exec3b12
exec3b13
exec3b2
exec3b3
exec3b4
exec3b5
exec3b6
exec3b7
exec3b8
exec3b9
facility1
facility10
facility11
facility12
facility13
facility14
facility15
facility16
facility17
facility2
facility3
facility4
facility5
facility6
facility7
facility8
facility9

Obviously the wanted result would be:

exec3b1
exec3b2
exec3b3
exec3b4
exec3b5
exec3b6
exec3b7
exec3b8
exec3b9
exec3b10
exec3b11
exec3b12
exec3b13
facility1
facility2
facility3
facility4
facility5
facility6
facility7
facility8
facility9
facility10
facility11
facility12
facility13
facility14
facility15
facility16
facility17
OpenOffice 3.1 on Windows Vista
User avatar
Hagar Delest
Moderator
Posts: 33629
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Sorting 1 thru 19 correctly

Post by Hagar Delest »

procadman wrote: Thu Feb 20, 2025 6:05 am Here is a sample of the ~350 records output:
[...]
That would have been great to have it in your first post so that it shows precisely what your data look like.
But the root cause is the same as said in the other topics: your strings contain text, they are therefore considered as text and sorted based on their ASCII value, that doesn't separate the numbers from the text part.
They are workarounds, using a helper column to separate both parts.
Lupp wrote: Wed Feb 19, 2025 2:21 pm LibreOffice has a sorting option "Enable natural sort" which would produce the results you (OQer) expected in the given case.
However, the variants of texts containing numerical parts are many, and the feature is of limited vaue.
Works pretty fine in this case:
Natural_sort.png
Natural_sort.png (14.08 KiB) Viewed 4601 times
Please add [Solved] at the beginning of the title in your first post (top of the topic) with the button if your issue has been fixed.
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE 7 Gigi) and 25.2 portable on Windows 11.
User avatar
Lupp
Volunteer
Posts: 3756
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Sorting 1 thru 19 correctly

Post by Lupp »


LibO V25.2 has significantly changed the layout of option dialogs. Instead of tabs, there is now a kind of panel for the first level of selection.


Verry sorry! This is not the case for the sorting dialog.
Last edited by Lupp on Thu Feb 20, 2025 3:28 pm, edited 2 times in total.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
Posts: 3756
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Sorting 1 thru 19 correctly

Post by Lupp »

As I already hinted alphanumeric data containing numeric parts can occur in many different ways. A feature (in LibO) working as expected in a specific case may well fail in similar but different cases - or after a slight extension of what you already had.
Using such data should therefore always be based on a well considered and very strict format.
Example:
2025/facilty_/004
2021/exec3b/999
sort well even without "natural sort".
Their synatctial components are each of a fix length, and mandatory delimiters help to disambiguate cases which may possibly occur in the future. If (e.g) longer character sequences must be allowed for the middle part, a conversion of old data to the new format will also be simple.
Generally an extra column for each part of the compound information is preferable. It allows (e.g) to make the second part the most significant for another sort. Where a compound is wanted in addition it can be created by a formula in a very simple way. Columns are very cheap! And they can easily be hidden (as a group where needed) if the user feels they spoil the view.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Locked