Forum Discussion
Split a column by rows
- Jul 24, 2020
If you convert your raw data into an Excel Table and rename the Excel Table as "UserData", you may create a blank query and place the following M code into Advanced Editor and load the data back to the Sheet.
let Source = Excel.CurrentWorkbook(){[Name="UserData"]}[Content], #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1), #"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 2), type number), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-US")[Modulo]), "Modulo", "UserName"), #"Filled Down" = Table.FillDown(#"Pivoted Column",{"0"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([1] <> null)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"0", "UserName"}, {"1", "Email Address"}}) in #"Renamed Columns"
The output will be like this...
Please refer to the attached for more details.
If you convert your raw data into an Excel Table and rename the Excel Table as "UserData", you may create a blank query and place the following M code into Advanced Editor and load the data back to the Sheet.
let
Source = Excel.CurrentWorkbook(){[Name="UserData"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
#"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 2), type number),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Inserted Modulo", {{"Modulo", type text}}, "en-US")[Modulo]), "Modulo", "UserName"),
#"Filled Down" = Table.FillDown(#"Pivoted Column",{"0"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([1] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"0", "UserName"}, {"1", "Email Address"}})
in
#"Renamed Columns"
The output will be like this...
Please refer to the attached for more details.
- Stephen_KaneJul 24, 2020Copper Contributor
- Subodh_Tiwari_sktneerJul 24, 2020Silver Contributor
You're welcome Stephen! Glad it worked as desired.
- Lor3nzoMar 13, 2021Copper Contributor
I'm stuck on a similar issue of @Stephen_Kane.
I'm new here in the Community and I hope that Subodh_Tiwari_sktneer or someone else can help me to come up with a solution.
I have 3 columns as follow:
Order ID Attributes Values 123 Quantity 1 123 Amount $50 123 Product Name Test Product 1 123 Category Test Category 1 123 Quantity 2 123 Amount $100 123 Product Name Test Product 2 123 Category Test Category 2 234 Quantity 1 234 Amount $70 234 Product Name Test Product 3 234 Category Test Category 3 234 Quantity 1 234 Amount $100 234 Product Name Test Product 1 234 Category Test Category 1 As you can see I have duplicate ATTRIBUTES and different type of VALUES (numbers, currencies and text).
I need to split each single attribute in columns with the corresponding value below.
Thank you in advance for helping me with this!