Forum Discussion
telesforo1969
Helper V
1 year agoseparate values from two columns at the same time power query
I appreciate the support for separating values from two columns at the same time as indicated in the image, I am using the function Splitter.SplitTextByCharacterTransition. The image in Excel shows t...
- 1 year ago
Hi,
This M code in Power Query works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Zip({Text.Split([Tipo],":"),Text.Split([Mezcla],":")})), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"), Custom1 = Table.TransformColumns(#"Expanded Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), "#(tab)"), type text}), #"Split Column by Delimiter" = Table.SplitColumn(Custom1, "Custom", Splitter.SplitTextByDelimiter("#(tab)", QuoteStyle.Csv), {"TipoTransformado", "MezclaTransformado"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Tipo", type text}, {"Mezcla", type text}, {"TipoTransformado", type text}, {"MezclaTransformado", Int64.Type}}) in #"Changed Type"Hope this helps.
Greg_Deckler
Community Champion
1 year agotelesforo1969 One way to do this is to import the table twice and in both split the columns by ":". Then you simply remove the first two columns for Tipo and Mezcla in one query, remove the second two columns for Tipo and Mezcla in the other. Rename the columns and append. Like this:
Table query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcrRyUtJRMjOwMjFQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tipo = _t, Mezcla = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Tipo", type text}, {"Mezcla", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Splitter.SplitTextByCharacterTransition( { "A".."z" }, { ":" } )( [Tipo] )),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Custom"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Tipo", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Tipo.1", "Tipo.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Tipo.1", type text}, {"Tipo.2", type text}}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Mezcla", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Mezcla.1", "Mezcla.2"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Mezcla.1", Int64.Type}, {"Mezcla.2", Int64.Type}}),
#"Removed Columns1" = Table.RemoveColumns(#"Changed Type2",{"Tipo.2", "Mezcla.2"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Tipo.1", "Tipo"}, {"Mezcla.1", "Mezcla"}})
in
#"Renamed Columns"
Table (2) query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcrRyUtJRMjOwMjFQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tipo = _t, Mezcla = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Tipo", type text}, {"Mezcla", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Tipo", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Tipo.1", "Tipo.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Tipo.1", type text}, {"Tipo.2", type text}}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Mezcla", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Mezcla.1", "Mezcla.2"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Mezcla.1", Int64.Type}, {"Mezcla.2", Int64.Type}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Tipo.1", "Mezcla.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Tipo.2", "Tipo"}, {"Mezcla.2", "Mezcla"}})
in
#"Renamed Columns"
Final table:
let
Source = Table.Combine({Table, #"Table (2)"})
in
Source
You can then set the Table and Table (2) queries to not load.
- telesforo19691 year ago
Helper V
Thank you for the support. I will try and let you know.