Forum Discussion
Help - Excel is sortin 10 before 2
Hi
My formula is
=transpose(sort(unique(reasons)))
The reasons name range is just reason 1, reason 2, reason 3 etc. all the way to 10.
Except it's not displaying order - Reason 10 is before Reason 2
12 Replies
- cheeseontoast101Copper Contributor
This is what I am trying to create on a visual level. As you can see though it's not in the right order although the reason count for each party is displaying correctly. The 0 after the nine needs to go as well.
- PeterBartholomew1Silver Contributor
In beta version of Excel there is the TEXTAFTER function that removes the need for SEARCH/MID. Singling out the numeric part of the string allows it to be used as the sort criterion
= TRANSPOSE(UNIQUE( SORTBY(reasons,VALUE(TEXTAFTER(reasons, " "))) ))
An alternative approach might be to edit the text to start with "Reason 01", so aligning alphabetical and numerical sort.
[As an aside, I always find it strange that spreadsheet column headers are sorted in a manner that conforms neither to alphabetical nor numeric ordering]
- SekoleyteIron Contributor
Hi. To sort them by number values try this one.
Reasons is a name of the combination of Reason 1;...; Reason 10
=TRANSPOSE(SORT(VALUE(MID(UNIQUE(Reasons);8;100))))Note: 8 in the formula is the start number of MID function. It means length of "Reason " +1 to catch the start of your numbers.
100 in the formula is the number of characters of MID function to after the start number. i thought that 100 characters are enough to catch numbers of reasons.
I put an excel file as well to be clearer for you. Do not forget to put a name before you try this formula or choose range instead of adding a name instead of "Reasons" in the formula.
- cheeseontoast101Copper ContributorHi
I've replicated this exactly and try to fiddle with it - keep getting the there's a problem with this formula error- SekoleyteIron ContributorHi there. i put an excel file for you in my answer. Check it if you have a problem. Probably you tried it before you create a name 🙂
- Subodh_Tiwari_sktneerSilver Contributor
That's because it is sorting text values not the numbers.
You may try something like this...
=TRANSPOSE(SORTBY(UNIQUE(reasons),SUBSTITUTE(reasons,"reason ","")*1))
- cheeseontoast101Copper ContributorI'm getting a value error
Here is my replication
=TRANSPOSE(SORTBY(UNIQUE(reasons),SUBSTITUTE(Reasons,"Reason 10 ","Reason 2")*1))- SergeiBaklanDiamond Contributor
Slightly modified formula suggested by Subodh_Tiwari_sktneer - you shall SUBSTITURE on unique values
=LET( u, UNIQUE(Reasons), SORTBY( u,SUBSTITUTE(u,"reason ","")*1) )
Forgot TRANSPOSE, but that doesn't matter.