Reputation: 1
I'm new to power bi.I tried split delimiter by | and it was creating multiple rows with each category matching with each amount value of the same order id. But, I want only corresponding values of the category and amount to be matched.
Upvotes: 0
Views: 43
Reputation: 2480
not sure if we have an easier way to solve this. Here is a workaround for you as a reference.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bVC7bsMwDPwVQ3NCiLQe0egEyJoA7RZ4cF0lNmDIhmQPAfrxpWoPCdCF4h3vjgJvN3Gq9iQR92gsOid24tiHbx9T8VNUceZ67cbgMzw3afZhHV2byUcWG+nAHZjQoPJTOlyx1RqcyQwCkqh3L5uUkyTZfLnf+9YXH8s0Df26Ygn9vESfeEpbMAeqd3+JTup//Z++7cI4jI/nG2CtBWJKEUg8mK0r9WsukjWoWFq1rU9pjFtk8zX8Ndtd8s9KBUozhaQNUA5GC8qIuv4F", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order ID" = _t, Category = _t, Amount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Order ID", type text}, {"Category", type text}, {"Amount", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Category", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Category.1", "Category.2", "Category.3", "Category.4", "Category.5"}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Amount", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Amount.1", "Amount.2", "Amount.3", "Amount.4", "Amount.5"}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter1", {"Order ID"}, "Attribute", "Value"),
#"Extracted Last Characters" = Table.TransformColumns(#"Unpivoted Other Columns", {{"Attribute", each Text.End(_, 1), type text}}),
#"Grouped Rows" = Table.Group(#"Extracted Last Characters", {"Order ID", "Attribute"}, {{"text", each Text.Combine([Value],","), type any}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Attribute"}),
#"Split Column by Delimiter2" = Table.SplitColumn(#"Removed Columns", "text", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"text.1", "text.2"}),
#"Changed Type4" = Table.TransformColumnTypes(#"Split Column by Delimiter2",{{"text.1", type text}, {"text.2", type number}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type4",{{"text.1", "Category"}, {"text.2", "Amount"}})
in
#"Renamed Columns"
Upvotes: 0