Forum Discussion
jerbear
Jul 30, 2020Copper Contributor
Help sorting in Excel
I need help getting the after sort results in my photo.
PeterBartholomew1
Aug 04, 2020Silver Contributor
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
LoadToTableThank you for the model code and guidance.
SergeiBaklan
Aug 04, 2020Diamond Contributor
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.