Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Transpose groups of rows into Columns

Hello! 

 

Could you please assist how can i group transpose rows into columns:

Input:

Output:

The original numbers of rows is quite big but they are repetetive.

 

Column 1Column 2
Product_id1234
Date01-2014-20
Unit1
Revenue4321
Product_id2345
Date01-2014-21
Unit2
Revenue4321
Product_id3211
Date01-2014-22
Unit3
Revenue12345

 

Thanks!

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    For this scenario, I would split the table into page sizes of 4 rows, and then Transpose and Promote the Headers in the list of tables.  Then you can just expand them!

     

    let
    Source = Excel.CurrentWorkbook(){[Name="Products"]}[Content],
    Custom1 = List.Transform(Table.Split(Source, 4), each Table.Transpose(_)),
    Custom2 = List.Transform(Custom1, each Table.PromoteHeaders(_)),
    #"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandTableColumn(#"Converted to Table", "Column1", {"Product_id", "Date", "Unit", "Revenue"}, {"Product_id", "Date", "Unit", "Revenue"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"Product_id", type text}, {"Date", type text}, {"Unit", type text}, {"Revenue", type text}})
    in
    #"Changed Type"

     

    --Nate

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    For this scenario, I would split the table into page sizes of 4 rows, and then Transpose and Promote the Headers in the list of tables.  Then you can just expand them!

     

    let
    Source = Excel.CurrentWorkbook(){[Name="Products"]}[Content],
    Custom1 = List.Transform(Table.Split(Source, 4), each Table.Transpose(_)),
    Custom2 = List.Transform(Custom1, each Table.PromoteHeaders(_)),
    #"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandTableColumn(#"Converted to Table", "Column1", {"Product_id", "Date", "Unit", "Revenue"}, {"Product_id", "Date", "Unit", "Revenue"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"Product_id", type text}, {"Date", type text}, {"Unit", type text}, {"Revenue", type text}})
    in
    #"Changed Type"

     

    --Nate