Forum Discussion

profindir's avatar
profindir
New Member
9 years ago
Solved

Transpose table

Can you help me to transpose this table to that in Power BI Desktop.   Thank you.  
  • MarcelBeug's avatar
    MarcelBeug
    9 years ago

    An alternative solution with far less code can be achieved with more advanced coding, using Table.Partition.

     

    let
        Source = Table1,
        #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
        Partitioned = Table.Partition(#"Added Index","Index",3, each _),
        TableFromColumns = Table.FromColumns(
                                {Partitioned{0}[Column2],
                                 Partitioned{0}[Column1],
                                 Partitioned{1}[Column1],
                                 Partitioned{2}[Column1]}),
        #"Promoted Headers" = Table.PromoteHeaders(TableFromColumns, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",
                               {{"Invoice Nº", type text},
                                {"Period", type date},
                                {"Sum", type number},
                                {"Quantity", Int64.Type}})
    in
        #"Changed Type"

    Table.Partition creates a list with separate tables, of which the first table contains all data from the 1st, 4th, 7th etc. row, the second table from the 2nd, 5th, 8th etc row, the third table from the 3rd, 6th, 9th etc. row.

     

    Now the appropriate columns can be combined with Table.FromColumns.