Help

Re: Sorting Numbers in Text Fields: Unexpected Behavior

Solved
Jump to Solution
1065 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Matt_Kennedy1
7 - App Architect
7 - App Architect

Here’s how Airtable is sorting my text col:
2XY
11A
This logic seems to be unique to Airtable: 11 is after 2 (not 1 is before 2, as expected). This causes problems trying to match a sorted list in Airtable with the same list sorted in another program.

Is this a bug, intended behavior that can be worked around, or something else?

Thanks!

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

It’s actually sorting logically, but the logic may not be clear based on those two items alone. I added those to a table along with some other items, and I think the pattern might be more clear after seeing this:

Screen Shot 2021-09-28 at 11.04.27 AM

Long story short, it’s sorting by number first, then by the characters after the number (if any are present). It’s not sorting character by character.

A simple way to force the sort to go character by character is to put spaces between each character. These are the same items with the same sort settings:

Screen Shot 2021-09-28 at 11.08.05 AM

Thankfully you don’t need to apply this change manually. This formula will create the desired output, and you can then sort by the formula field (which can be hidden).

REGEX_REPLACE({Your Field Here}, "(.)", "$1 ")

Here’s the original data in the left column, and the formula output in the right, with the sort applied to the formula field.

Screen Shot 2021-09-28 at 11.15.05 AM

See Solution in Thread

3 Replies 3
Justin_Barrett
18 - Pluto
18 - Pluto

It’s actually sorting logically, but the logic may not be clear based on those two items alone. I added those to a table along with some other items, and I think the pattern might be more clear after seeing this:

Screen Shot 2021-09-28 at 11.04.27 AM

Long story short, it’s sorting by number first, then by the characters after the number (if any are present). It’s not sorting character by character.

A simple way to force the sort to go character by character is to put spaces between each character. These are the same items with the same sort settings:

Screen Shot 2021-09-28 at 11.08.05 AM

Thankfully you don’t need to apply this change manually. This formula will create the desired output, and you can then sort by the formula field (which can be hidden).

REGEX_REPLACE({Your Field Here}, "(.)", "$1 ")

Here’s the original data in the left column, and the formula output in the right, with the sort applied to the formula field.

Screen Shot 2021-09-28 at 11.15.05 AM

Great solution!

I do understand that the sort is logical, but I am surprised that this logic does not conform to standard expectations. Perhaps this was an idea dreamed up as a cool feature (autodetect numerical series in strings and treat them as numbers). But since I do a lot of moving data back and forth between apps, it is cumbersome to account for two different sorting paradigms. I like your formula option. Didn’t know Airtable had Regex - Cool!

A) Its only "sort of" sorting logical... as it's not logical to not conform to standards!

B) Plus if they really thought this was a "cool new feature" that detects strings of numbers (instead of character by character) they would have extended that to a decimal string, because its wrecking my ability to sort my decimals (see example in picture below).

(I don't want to have to include insignificant decimal places as with zeroes... ie "1.10" and "1.30").

(And I also want to suffix each number with "mph" text, so I have to use the Text field)

(I don't want to add complications to the table, by having to patch it with additional formula fields, which then also separates editability and viewability, and duplicates where this simple data is stored (one for viewing, one for editing)...

In summary they should either A) conform to sorting standards, or B) go the full mile with their "special" number-string detection, to be smart enough to include decimals.

Screenshot 2023-03-28 at 16.33.54.png