Forum Discussion
To convert vertical table into horizontal table in powerbi
- 6 years ago
Hi William_Moreno ,
We can use some transformations in Power Query Editor to meet your requirement.
1. Copy the table and delete the Mov column.
2. Group the Order_ID column.
3. Add a custom column to get the Date column.
4. Extract the Custom column by comma.
5. At last, split the column.
The whole M query as following,
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMAUhQyUdINsUSBoZGBnoW+gbGijF6uCTNyQgb0RA3piAvAmKvBFY3gwmb6hviF/aCL+0MX5pAnabKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order_ID = _t, Mov = _t, Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Mov"}), #"Grouped Rows" = Table.Group(#"Removed Columns", {"Order_ID"}, {{"Data", each _, type table [Order_ID=nullable text, Date=nullable date]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Data],"Date")), #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}), #"Removed Columns1" = Table.RemoveColumns(#"Extracted Values",{"Data"}), #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3", "Custom.4", "Custom.5"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Order_ID", Int64.Type}, {"Custom.1", type date}, {"Custom.2", type date}, {"Custom.3", type date}, {"Custom.4", type date}, {"Custom.5", type date}}) in #"Changed Type1"If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
Hi William_Moreno ,
We can use some transformations in Power Query Editor to meet your requirement.
1. Copy the table and delete the Mov column.
2. Group the Order_ID column.
3. Add a custom column to get the Date column.
4. Extract the Custom column by comma.
5. At last, split the column.
The whole M query as following,
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMAUhQyUdINsUSBoZGBnoW+gbGijF6uCTNyQgb0RA3piAvAmKvBFY3gwmb6hviF/aCL+0MX5pAnabKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order_ID = _t, Mov = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Mov"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"Order_ID"}, {{"Data", each _, type table [Order_ID=nullable text, Date=nullable date]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Data],"Date")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Columns1" = Table.RemoveColumns(#"Extracted Values",{"Data"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3", "Custom.4", "Custom.5"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Order_ID", Int64.Type}, {"Custom.1", type date}, {"Custom.2", type date}, {"Custom.3", type date}, {"Custom.4", type date}, {"Custom.5", type date}})
in
#"Changed Type1"
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.