Forum Discussion

DarrylJP's avatar
DarrylJP
Copper Contributor
Nov 13, 2022
Solved

Sorting Numbers Withing a Text String

Usually I can think of at least a thought process of where to go, but stumped on this one...

I have a text field with a six digit text string, as an example '201210', i would like to sort those six digits into a new text string, so in the example above i would end up with a new text string '221100'.

 

Anyone have an idea where to start with th

3 Replies

  • davidleal's avatar
    davidleal
    Iron Contributor

    If you have the input text in A1, then:

     

    =LET(x, SUBSTITUTE(A1,"'",""), 
     "'"&TEXTJOIN("",,SORT(MID(x, SEQUENCE(LEN(x)),1),,-1))&"'")

     

    it returns: '221100'

     

    • DarrylJP's avatar
      DarrylJP
      Copper Contributor
      Thanks Harun24HR! My brain would have never gone there, greatly appreciated!