Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kmkwongaa
Helper I
Helper I

Can I split the column into row with source and destination?

split.PNG

I have the above column. I want to split the string into row.

I know that I could split it by delimiter.

 

But I want to specify the source and destination for the path. 

e.g. for first row, [1_2_3_11_9_14_13_14_3_14_15_23_30_31_32],

I would like to split to the following format:

From    To

1            2

2            3

3            11 

11           9

etc

 

so that I can visualize the path with network plot.

How can I do this?

 

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @kmkwongaa ,

 

You could use split to two tables :one has cleared the first value and another one has cleared the last value. Then merge or combine these two tables.

You could refer to the following codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMow3ijeON4k3VYrViVYyiTeLt1SKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"_"}, QuoteStyle.Csv, true), {"Column1.1", "Column1.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Column1.2"}),
    #"Split Column by Delimiter2" = Table.ExpandListColumn(Table.TransformColumns(#"Removed Columns", {{"Column1.1", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1.1"),
    #"Added Index" = Table.AddIndexColumn(#"Split Column by Delimiter2", "Index", 0, 1),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"_"}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Column1.1"}),
    #"Split Column by Delimiter3" = Table.ExpandListColumn(Table.TransformColumns(#"Removed Columns1", {{"Column1.2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1.2"),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each #"Split Column by Delimiter3"[[Column1.2]]{[Index]}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Column1.2"}, {"Custom.Column1.2"}),
    #"Removed Columns2" = Table.RemoveColumns(#"Expanded Custom",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns2",{{"Column1.1", "From"}, {"Custom.Column1.2", "To"}})
in
    #"Renamed Columns"

Here is the sample and result.

1-1.PNG1-2.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @kmkwongaa ,

 

You could use split to two tables :one has cleared the first value and another one has cleared the last value. Then merge or combine these two tables.

You could refer to the following codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMow3ijeON4k3VYrViVYyiTeLt1SKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"_"}, QuoteStyle.Csv, true), {"Column1.1", "Column1.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Column1.2"}),
    #"Split Column by Delimiter2" = Table.ExpandListColumn(Table.TransformColumns(#"Removed Columns", {{"Column1.1", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1.1"),
    #"Added Index" = Table.AddIndexColumn(#"Split Column by Delimiter2", "Index", 0, 1),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"_"}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Column1.1"}),
    #"Split Column by Delimiter3" = Table.ExpandListColumn(Table.TransformColumns(#"Removed Columns1", {{"Column1.2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1.2"),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each #"Split Column by Delimiter3"[[Column1.2]]{[Index]}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Column1.2"}, {"Custom.Column1.2"}),
    #"Removed Columns2" = Table.RemoveColumns(#"Expanded Custom",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns2",{{"Column1.1", "From"}, {"Custom.Column1.2", "To"}})
in
    #"Renamed Columns"

Here is the sample and result.

1-1.PNG1-2.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.