ahagman
ahagman

Reputation: 73

Power Query List To Table

I have trouble transforming a list to table.

So this:

{"123","1.1","321","12","345","345"}

should be transformed to this

{{"123","1.1"},{"321","12"},{"345","345"}}

even better if there where a function that you could easily transform also to this

{{"123","1.1","321"},{"12","345","345"}}

Upvotes: 2

Views: 4443

Answers (1)

Oğuz Yıldız
Oğuz Yıldız

Reputation: 241

Might not be the best way:

let
    ListToTable = (sourceList as list, columnCount as number) as table =>
    let
        #"Converted to Table" = Table.FromList(sourceList , Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1),
        #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, columnCount), Int64.Type}}),
        #"Grouped Rows" = Table.FromRecords(List.Transform(Table.Group(#"Integer-Divided Column", {"Index"}, {{"Rows", each Table.SelectColumns(_, "Column1"), type table}})[Rows], (rowTable) => Table.First(Table.Transpose(rowTable))))
    in
        #"Grouped Rows"
in
    ListToTable({1,2,3,4,5,6}, 3)

Upvotes: 3

Related Questions