Help sorting in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-1556527%22%20slang%3D%22en-US%22%3EHelp%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1556527%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20help%20getting%20the%20after%20sort%20results%20in%20my%20photo.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22excel%20sort%20issue.png%22%20style%3D%22width%3A%20580px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F209086i10AC52127FDA95A8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22excel%20sort%20issue.png%22%20alt%3D%22excel%20sort%20issue.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1556527%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1556544%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1556544%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F745007%22%20target%3D%22_blank%22%3E%40jerbear%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20sort%20columns%20one%20by%20one%20without%20expanding%20the%20selection%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20385px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F209091i50D0E46CD37116E3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564368%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564368%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F745007%22%20target%3D%22_blank%22%3E%40jerbear%3C%2FA%3E%26nbsp%3BIn%20your%20example%20you%20have%20a%20range%20of%2010%20rows%20and%204%20columns%20containing%2035%20names%20an%205%20blanks.%20Your%20aim%20is%20to%20sort%20these%20in%20alphabetical%20order%20and%20display%20them%20side-by-side%20in%20groups%20of%20max%2010.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20suspect%20that%20your%20real%20situation%20isn't%20as%20straightforward%2C%20but%20am%20offering%20you%20a%20power%20query%20(PQ)%20solution%20that%20does%20exactly%20what%20you%20ask%20for%20in%20the%20example.%20I%20am%20fully%20aware%20that%20this%20is%20not%20the%20most%20elegant%20or%20dynamic%20solution.%20A%20real%20expert%20in%20PQ%20can%20probably%20come-up%20with%20a%20better%20way.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202020-08-04%20at%2007.41.35.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210122i2C55B78ED078B72E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Screenshot%202020-08-04%20at%2007.41.35.png%22%20alt%3D%22Screenshot%202020-08-04%20at%2007.41.35.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564487%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564487%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F745007%22%20target%3D%22_blank%22%3E%40jerbear%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20formula%20solution%20...%20IF%20you%20have%20the%20right%20version%20of%20Excel!%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20k%2C%20SEQUENCE(40%2C1%2C0)%2C%0A%20%20rowNum%2C%20MOD(k%2C10)%2C%0A%20%20colNum%2C%20QUOTIENT(k%2C10)%2C%0A%20%20list%2C%20INDEX(Table1%2C1%2BrowNum%2C1%2BcolNum)%2C%0A%20%20sorted%2C%20SORT(list)%2C%0A%20%20idxArray%2C%20SEQUENCE(10%2C1%2C0)%2B10*SEQUENCE(1%2C4%2C0)%2C%0A%20%20stacked%2C%20INDEX(sorted%2C%201%2BidxArray)%2C%0A%20%20IF(stacked%26lt%3B%26gt%3B0%2Cstacked%2C%20%22%22)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564709%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564709%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F745007%22%20target%3D%22_blank%22%3E%40jerbear%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EA%20formula%20solution%2C%20provided%20you%20have%20the%20correct%20version%20of%20Excel!%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20unpivot%2C%20LET(%0A%20%20%20%20%20k%2C%20SEQUENCE(40%2C1%2C0)%2C%0A%20%20%20%20%20rowNum%2C%20MOD(k%2C10)%2C%0A%20%20%20%20%20colNum%2C%20QUOTIENT(k%2C10)%2C%0A%20%20%20%20%20INDEX(Table1%2C1%2BrowNum%2C1%2BcolNum)%20)%2C%0A%20%20sort%2C%20LET(%0A%20%20%20%20%20sorted%2C%20SORT(unpivot)%2C%0A%20%20%20%20%20IF(sorted%26lt%3B%26gt%3B0%2C%20sorted%2C%20%22%22)%20)%2C%0A%20%20repivot%2C%20LET(%0A%20%20%20%20%20idxArray%2C%20SEQUENCE(10%2C1%2C0)%2B10*SEQUENCE(1%2C4%2C0)%2C%0A%20%20%20%20%20INDEX(sort%2C%201%2BidxArray)%20)%2C%0A%20%20repivot%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20refactored%20the%20formula%20because%20it%20was%20you%20that%20first%20demonstrated%20the%20nested%20LET%20to%20me!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564724%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564724%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20adding%20an%20index%20column%20and%20unpivoting%20other%20columns%20involve%20fewer%20queries%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564802%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564802%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20idea%20was%20in%20the%20air%2C%20if%20I%20found%20that%20an%20hour%20earlier%20than%20you%20that%20means%20nothing.%3C%2FP%3E%0A%3CP%3EEven%20if%20LET()%20is%20on%20Current%20(Preview)%20now%20I%20still%20avoid%20to%20use%20it%20in%20MTC%20discussion%2C%20will%20wait%20availability%20at%20least%20on%20Current.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564788%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564788%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3BGuess%20so.%20Didn't%20think%20about%20that%20one.%20Much%20better.%20Thanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3ESee%20attached.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564915%22%20slang%3D%22de-DE%22%3ESubject%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564915%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F745007%22%20target%3D%22_blank%22%3E%40jerbear%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EA%20small%20solution%20would%20be%20a%20VBA%20solution%20like%20the%20one%20in%20the%20attached%20file.%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EIs%20only%20an%20additional%20suggestion%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESub%20Sort()%0ADim%20strSpalte%20As%20String%0ADim%20strBereich%20As%20String%0A%0A'Parameter%0AstrBereich%20%3D%20%22A1%3AB11%22%20'Area%0AstrSpalte%20%3D%20%22A%22%20%20'column%0A%0A'Sort%0AWith%20Tabelle1%20'Sheet%0ARange(strBereich).Sort%20_%0A%20Key1%3A%3DRange(strSpalte%20%26amp%3B%20%221%22)%2C%20Order1%3A%3DxlAscending%2C%20_%0A%20Header%3A%3DxlYes%2C%20MatchCase%3A%3DTrue%0AEnd%20With%0AEnd%20Sub%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EIf%20you%20liked%20one%20of%20the%20suggested%20solutions%2C%20please%20click%20on%20it%20as%20the%20correct%20answer%2C%20if%20possible%20with%20a%20like%20(thumbs%20up).%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3EIf%20none%20is%20the%20solution%20you%20are%20looking%20for%2C%20please%20give%20us%20a%20quick%20feedback.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%20%3CSPAN%3EBest%20regards%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ENikolino%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564970%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564970%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20would%20do%20it!%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1565083%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1565083%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20play%20with%20coding%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22tblNames%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20SortedSource%20%3D%20Table.FromColumns(%0A%20%20%20%20%20%20%20%20List.Split(%0A%20%20%20%20%20%20%20%20%20%20%20%20List.Sort(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20List.Distinct(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20List.RemoveNulls(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20List.Union(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Table.ToColumns(Source)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20Table.RowCount(Source)%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20Table.ColumnNames(Source)%0A%20%20%20%20)%0Ain%0A%20%20%20%20SortedSource%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1565796%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1565796%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22%3CSPAN%3E%3CEM%3EEven%20if%20LET()%20is%20on%20Current%20(Preview)%20now%20I%20still%20avoid%20to%20use%20it%20in%20MTC%20discussion%3C%2FEM%3E%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20was%20going%20to%20say%20that%20was%20because%20you%20are%20more%20responsible%20than%20I%2C%20and%20simply%20seek%20to%20help%2C%20whereas%20I%20look%20for%20challenges%20that%20allow%20me%20to%20develop%20the%20techniques%20I%20can%20apply%20to%20a%20range%20of%20problems.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EWith%20your%20nested%20PQ%20solution%2C%20I%20am%20not%20so%20sure!%26nbsp%3B%20Whereas%2C%20with%20the%20LET%20function%2C%20I%20introduced%20local%20names%20to%20provide%20documentation%20and%20remove%20nesting%2C%20you%20have%20travelled%20a%20similar%20road%20in%20the%20opposite%20direction%2C%20albeit%20with%20a%20striking%20indentation%20pattern.%26nbsp%3B%20I%20expect%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3Bcoped%20just%20fine%2C%20but%20it%20took%20me%20a%20while%20before%20I%20settled%20on%20reading%20from%20the%20deepest%20nesting%20outwards%20and%20I%20also%20had%20to%20come%20to%20terms%20with%20some%20list%20methods%20that%20I%20would%20not%20be%20able%20to%20access%20from%20the%20GUI!%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20still%20have%20the%20feeling%20that%20I%20am%20not%20going%20to%20become%20fluent%20with%20such%20a%20style%20anytime%20soon!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%20anyway.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1565897%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1565897%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%2C%20if%20I%20do%20this%20query%20from%20scratch%20I'd%20do%20it%20approximately%20the%20same%20way%20as%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3Bdid.%20Reasons%20-%20more%20UI%20is%20better%20for%20shared%20solutions%3B%20UI%20is%20usually%20better%20from%20maintenance%20point%20of%20view.%20Plus%20from%20performance%20point%20of%20view%20Power%20Query%20is%20better%20optimized%20to%20work%20with%20tables%20rather%20than%20with%20lists.%20However%2C%20performance%20is%20half%20a%20technology%2C%20another%20half%20is%20the%20art.%20Approach%20depends%20on%20concrete%20case.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENested%20list%20functions%20are%20only%20to%20demonstrate%20alternatives.%20I%20fully%20agree%2C%20from%20usability%20point%20of%20view%20same%20code%20organised%20by%20steps%20is%20much%20better%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22tblNames%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20%0A%20%20%20%20combineColumnsInOneList%20%3D%20List.Union(Table.ToColumns(Source))%2C%0A%20%20%20%20removeNullsFromList%20%20%20%20%20%3D%20List.RemoveNulls(combineColumnsInOneList)%2C%0A%20%20%20%20removeDuplicates%20%20%20%20%20%20%20%20%3D%20List.Distinct(removeNullsFromList)%2C%0A%20%20%20%20sortList%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20List.Sort(removeDuplicates)%2C%0A%20%20%20%20rowsInTable%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20Table.RowCount(Source)%2C%0A%20%20%20%20splitListOnFutureColumns%3D%20List.Split(sortList%2CrowsInTable)%2C%0A%20%20%20%20generateSortedTable%20%20%20%20%20%3D%20Table.FromColumns(%0A%20%20%20%20%20%20%20%20splitListOnFutureColumns%2C%0A%20%20%20%20%20%20%20%20Table.ColumnNames(Source)%0A%20%20%20%20)%0Ain%0A%20%20%20%20generateSortedTable%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENested%20variant%20is%20bit%20better%20only%20from%20development%20point%20of%20view%2C%20at%20least%20for%20me.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566063%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566063%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20is%20nothing%20special%20about%20the%20result%3B%20the%20point%20is%20that%20this%20was%20the%20first%20time%20I%20had%20ever%20put%20together%20M%20code%20using%20the%20advanced%20editor!%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22tblNames%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20SortedList%20%3D%20List.Sort(%0A%20%20%20%20%20%20%20%20List.Distinct(%0A%20%20%20%20%20%20%20%20%20%20%20%20List.RemoveNulls(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20List.Union(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Table.ToColumns(Source)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%20%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%2C%0A%20%20%20%20n%20%3D%201%2BNumber.IntegerDivide(List.Count(SortedList)%2C4)%2C%0A%20%20%20%20LoadToTable%20%3D%20Table.FromColumns(%0A%20%20%20%20%20%20%20%20List.Split(SortedList%2Cn)%2C%0A%20%20%20%20%20%20%20%20Table.ColumnNames(Source)%0A%20%20%20%20)%0Ain%0A%20%20%20%20LoadToTable%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThank%20you%20for%20the%20model%20code%20and%20guidance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566095%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566095%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20only%20what%20is%20discussable%20here%20is%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3En%20%3D%201%2BNumber.IntegerDivide(List.Count(SortedList)%2C4)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Ewhy%20the%20magic%20%3CSTRONG%3E4%3C%2FSTRONG%3E%20appeared.%20But%20that's%20not%20clear%20from%20the%20specification%20-%20shall%20resulting%20table%20be%20the%20same%20size%20as%20the%20source%2C%20or%20or%20only%20same%20number%20of%20columns%2C%20or%20some%20number%20of%20rows%20and%20doesn't%20matter%20how%20many%20columns.%20If%20%3CSTRONG%3E4%3C%2FSTRONG%3E%20is%20predefined%20when%20no%20problems%2C%20otherwise%20it%20shall%20be%20calculatable.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566124%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20sorting%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566124%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrue.%26nbsp%3B%20The%204%20should%20have%20been%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ETable.Column.Count(Source)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BI%20wanted%20to%20change%20the%20functionality%2C%20just%20for%20the%20same%20of%20doing%20something%20different%20as%20an%20exercise.%26nbsp%3B%20The%20useful%20side%20effect%20is%20that%20the%20process%20copes%20better%20with%20the%20situation%20in%20which%20more%20than%20a%20quarter%20of%20the%20cells%20are%20null%2C%20which%20potentially%20reduces%20the%20output%20to%203%20columns%2C%20depending%20on%20the%20algorithm.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20decided%20to%20maintain%20the%20number%20of%20columns%20but%20reduce%20the%20records.%26nbsp%3B%20I%20do%20not%20know%20what%20the%20OP%20would%20have%20wanted%2C%20but%20I%20suspect%20he%20has%20long%20since%20left%20the%20discussion.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

I need help getting the after sort results in my photo.

 

excel sort issue.png

 

14 Replies
Highlighted

@jerbear 

You may sort columns one by one without expanding the selection

image.png

Highlighted

@jerbear In your example you have a range of 10 rows and 4 columns containing 35 names an 5 blanks. Your aim is to sort these in alphabetical order and display them side-by-side in groups of max 10.

 

I suspect that your real situation isn't as straightforward, but am offering you a power query (PQ) solution that does exactly what you ask for in the example. I am fully aware that this is not the most elegant or dynamic solution. A real expert in PQ can probably come-up with a better way.

Screenshot 2020-08-04 at 07.41.35.png

 

 

Highlighted

@jerbear 

A formula solution, provided you have the correct version of Excel!

 

= LET(
  unpivot, LET(
     k, SEQUENCE(40,1,0),
     rowNum, MOD(k,10),
     colNum, QUOTIENT(k,10),
     INDEX(Table1,1+rowNum,1+colNum) ),
  sort, LET(
     sorted, SORT(unpivot),
     IF(sorted<>0, sorted, "") ),
  repivot, LET(
     idxArray, SEQUENCE(10,1,0)+10*SEQUENCE(1,4,0),
     INDEX(sort, 1+idxArray) ),
  repivot )

 

 

@Sergei Baklan 

I refactored the formula because it was you that first demonstrated the nested LET to me!

Highlighted

@Riny_van_Eekelen 

Would adding an index column and unpivoting other columns involve fewer queries?

Highlighted

@Peter Bartholomew Guess so. Didn't think about that one. Much better. Thanks!

 

See attached.

Highlighted

@Peter Bartholomew 

The idea was in the air, if I found that an hour earlier than you that means nothing.

Even if LET() is on Current (Preview) now I still avoid to use it in MTC discussion, will wait availability at least on Current.

Highlighted

@jerbear 

A small solution would be a VBA solution like the one in the attached file. Is only an additional suggestion

 

Sub Sort()
Dim strSpalte As String
Dim strBereich As String

'Parameter
strBereich = "A1:B11" 'Area
strSpalte = "A"  'column

'Sort
With Tabelle1 'Sheet
Range(strBereich).Sort _
 Key1:=Range(strSpalte & "1"), Order1:=xlAscending, _
 Header:=xlYes, MatchCase:=True
End With
End Sub

 

If you liked one of the suggested solutions, please click on it as the correct answer, if possible with a like (thumbs up). If none is the solution you are looking for, please give us a quick feedback.


Best regards,
Nikolino
I know I don't know anything (Socrates)

Highlighted

@Riny_van_Eekelen 

That would do it!  

Highlighted

@Riny_van_Eekelen 

To play with coding

let
    Source = Excel.CurrentWorkbook(){[Name="tblNames"]}[Content],
    SortedSource = Table.FromColumns(
        List.Split(
            List.Sort(
                List.Distinct(
                    List.RemoveNulls(
                        List.Union(
                            Table.ToColumns(Source)
                        )
                    )
                )
            ),
            Table.RowCount(Source)
        ),
     Table.ColumnNames(Source)
    )
in
    SortedSource

 

Highlighted

@Sergei Baklan 

"Even if LET() is on Current (Preview) now I still avoid to use it in MTC discussion"

I was going to say that was because you are more responsible than I, and simply seek to help, whereas I look for challenges that allow me to develop the techniques I can apply to a range of problems.

 

With your nested PQ solution, I am not so sure!  Whereas, with the LET function, I introduced local names to provide documentation and remove nesting, you have travelled a similar road in the opposite direction, albeit with a striking indentation pattern.  I expect @Riny_van_Eekelen coped just fine, but it took me a while before I settled on reading from the deepest nesting outwards and I also had to come to terms with some list methods that I would not be able to access from the GUI! 

 

I still have the feeling that I am not going to become fluent with such a style anytime soon!

Thanks anyway.

Highlighted

@Peter Bartholomew , if I do this query from scratch I'd do it approximately the same way as @Riny_van_Eekelen did. Reasons - more UI is better for shared solutions; UI is usually better from maintenance point of view. Plus from performance point of view Power Query is better optimized to work with tables rather than with lists. However, performance is half a technology, another half is the art. Approach depends on concrete case.

 

Nested list functions are only to demonstrate alternatives. I fully agree, from usability point of view same code organised by steps is much better

let
    Source = Excel.CurrentWorkbook(){[Name="tblNames"]}[Content],
    
    combineColumnsInOneList = List.Union(Table.ToColumns(Source)),
    removeNullsFromList     = List.RemoveNulls(combineColumnsInOneList),
    removeDuplicates        = List.Distinct(removeNullsFromList),
    sortList                = List.Sort(removeDuplicates),
    rowsInTable             = Table.RowCount(Source),
    splitListOnFutureColumns= List.Split(sortList,rowsInTable),
    generateSortedTable     = Table.FromColumns(
        splitListOnFutureColumns,
        Table.ColumnNames(Source)
    )
in
    generateSortedTable

Nested variant is bit better only from development point of view, at least for me.

Highlighted

@Sergei Baklan 

The is nothing special about the result; the point is that this was the first time I had ever put together M code using the advanced editor!

let
    Source = Excel.CurrentWorkbook(){[Name="tblNames"]}[Content],
    SortedList = List.Sort(
        List.Distinct(
            List.RemoveNulls(
                List.Union(
                    Table.ToColumns(Source)
                )
            ) 
        )
    ),
    n = 1+Number.IntegerDivide(List.Count(SortedList),4),
    LoadToTable = Table.FromColumns(
        List.Split(SortedList,n),
        Table.ColumnNames(Source)
    )
in
    LoadToTable

Thank you for the model code and guidance.

Highlighted

@Peter Bartholomew 

The only what is discussable here is

n = 1+Number.IntegerDivide(List.Count(SortedList),4)

why the magic 4 appeared. But that's not clear from the specification - shall resulting table be the same size as the source, or or only same number of columns, or some number of rows and doesn't matter how many columns. If 4 is predefined when no problems, otherwise it shall be calculatable.

Highlighted

@Sergei Baklan 

True.  The 4 should have been

Table.Column.Count(Source)

 I wanted to change the functionality, just for the same of doing something different as an exercise.  The useful side effect is that the process copes better with the situation in which more than a quarter of the cells are null, which potentially reduces the output to 3 columns, depending on the algorithm.

 

I decided to maintain the number of columns but reduce the records.  I do not know what the OP would have wanted, but I suspect he has long since left the discussion.