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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BrendenS
Frequent Visitor

New Column Based on Semicolon Column Values

Hello,

 

I have 3 columns Extension ID, Extension Pattern, and Ext Pattern Class Ref.  For a single Extension ID there are various amounts of Extension Patterns.  Each Extension Pattern has a color class assigned (Ext Pattern Class Ref). 

 

Because of the way the data is provided in the Ext Pattern Class Ref column (separated by semicolon) it is difficult to create a new column (Extension Pattern Classification) with the correct values.  Please share a workaround for this challenge if you have experienced. 

 

BrendenS_0-1708986731085.png

 

Thank you!

2 ACCEPTED SOLUTIONS

Hi @BrendenS ,

 

Here's the modified whole codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wco0IMQACEyUdJd9gdwMDQyDDvSg1NU8pVgcma2wBFPT3D3GCqANLWytEpubk5JdbK6Bw0XU5OjkGGBgakqgLYpcxOXYZG5CgyxLFhRjylkZA0aAAR6RQwWIKQpURblWGBiC7XHyQfKUUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extension ID" = _t, #"Extension Pattern" = _t, #"Ext Pattern Class Ref" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Extension ID", type text}, {"Extension Pattern", type text}, {"Ext Pattern Class Ref", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Ext Pattern Class Ref", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Ext Pattern Class Ref.1", type text}, {"Ext Pattern Class Ref.2", type text}, {"Ext Pattern Class Ref.3", type text}, {"Ext Pattern Class Ref.4", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Extension ID"}, {{"Count", each _, type table [Extension ID=nullable text, Extension Pattern=nullable text, Ext Pattern Class Ref.1=nullable text, Ext Pattern Class Ref.2=nullable text, Ext Pattern Class Ref.3=nullable text, Ext Pattern Class Ref.4=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Extension Pattern", "Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4", "Index"}, {"Extension Pattern", "Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4", "Index"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Expanded Custom", {"Extension ID", "Extension Pattern", "Index"}, "Attribute", "Value"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Changed Type2",{"Attribute.1"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns1", "Custom", each if [Attribute.2]=[Index] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom] = 1)),
    #"Trimmed Text" = Table.TransformColumns(#"Filtered Rows",{{"Value", Text.Trim, type text}}),
    #"Removed Columns2" = Table.RemoveColumns(#"Trimmed Text",{"Index", "Attribute.2", "Custom"})
in
    #"Removed Columns2"

Before:

vstephenmsft_0-1709194177325.png

 

After:

vstephenmsft_1-1709194185567.png

You can download my latest attachment for more information.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

View solution in original post

dufoq3
Super User
Super User

Hi @BrendenS, try this:

 

Result:

dufoq3_0-1709206313197.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wco0IMQACEyUdJd9gdwMDQyDDvSg1NU8pVgcma2wBFPT3D3GCqANLWytEpubk5JdbK6Bw0XU5OjkGGBgakqgLYpcxOXYZG5CgyxLFhRjylkZA0aAAR6RQwWIKQpURblWGBiC7XHyQfKUUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extension ID" = _t, #"Extension Pattern" = _t, #"Ext Pattern Class Ref" = _t]),
    Ad_PatternSplit = Table.AddColumn(Source, "Pattern Split", each Text.Split([Ext Pattern Class Ref], "; "), type list),
    GroupedRows = Table.Group(Ad_PatternSplit, {"Extension ID"}, {{"All", each Table.AddColumn(Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), "Extension Pattern Classification", (x)=> x[Pattern Split]{x[Index]}?, type text), type table}}),
    CombinedTables = Table.Combine(GroupedRows[All]),
    RemovedColumns = Table.RemoveColumns(CombinedTables,{"Pattern Split", "Index"})
in
    RemovedColumns

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Hi @BrendenS, try this:

 

Result:

dufoq3_0-1709206313197.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wco0IMQACEyUdJd9gdwMDQyDDvSg1NU8pVgcma2wBFPT3D3GCqANLWytEpubk5JdbK6Bw0XU5OjkGGBgakqgLYpcxOXYZG5CgyxLFhRjylkZA0aAAR6RQwWIKQpURblWGBiC7XHyQfKUUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extension ID" = _t, #"Extension Pattern" = _t, #"Ext Pattern Class Ref" = _t]),
    Ad_PatternSplit = Table.AddColumn(Source, "Pattern Split", each Text.Split([Ext Pattern Class Ref], "; "), type list),
    GroupedRows = Table.Group(Ad_PatternSplit, {"Extension ID"}, {{"All", each Table.AddColumn(Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), "Extension Pattern Classification", (x)=> x[Pattern Split]{x[Index]}?, type text), type table}}),
    CombinedTables = Table.Combine(GroupedRows[All]),
    RemovedColumns = Table.RemoveColumns(CombinedTables,{"Pattern Split", "Index"})
in
    RemovedColumns

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

v-stephen-msft
Community Support
Community Support

Hi @BrendenS ,

 

You can use split and unpivot to achieve this.

Here's the codes:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wco0IMTAwMFLSUQo28TAwMAUy3ItSU/OsFaBUZGpOTn65UqwOslrfYHcIgwi1jk6OAQbGuBXHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extension ID" = _t, #"Extension Patter" = _t, #"Ext Pattern Class Ref" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Extension ID", type text}, {"Extension Patter", type text}, {"Ext Pattern Class Ref", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Ext Pattern Class Ref", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Ext Pattern Class Ref.1", type text}, {"Ext Pattern Class Ref.2", type text}, {"Ext Pattern Class Ref.3", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Extension ID", "Extension Patter", "Index"}, "Attribute", "Value"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Attribute.1"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each if [Index]=[Attribute.2] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Attribute.2", "Custom"})
in
    #"Removed Columns1"

 

Or you can download my attachment for details. You can check what each step does from the steps that have been applied.

vstephenmsft_0-1709001411726.pngvstephenmsft_1-1709001432865.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

 

Hi Stephen, thank you for your help. While you have solved the exact use case for this limited example, is there a way to scale this in a dynamic way to fit a series of data with differentiating Extension Pattern to Ext Pattern Class Ref situations?  See example below...

 

BrendenS_2-1709058599108.png

 

Hi @BrendenS ,

 

Here's the modified whole codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wco0IMQACEyUdJd9gdwMDQyDDvSg1NU8pVgcma2wBFPT3D3GCqANLWytEpubk5JdbK6Bw0XU5OjkGGBgakqgLYpcxOXYZG5CgyxLFhRjylkZA0aAAR6RQwWIKQpURblWGBiC7XHyQfKUUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Extension ID" = _t, #"Extension Pattern" = _t, #"Ext Pattern Class Ref" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Extension ID", type text}, {"Extension Pattern", type text}, {"Ext Pattern Class Ref", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Ext Pattern Class Ref", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Ext Pattern Class Ref.1", type text}, {"Ext Pattern Class Ref.2", type text}, {"Ext Pattern Class Ref.3", type text}, {"Ext Pattern Class Ref.4", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Extension ID"}, {{"Count", each _, type table [Extension ID=nullable text, Extension Pattern=nullable text, Ext Pattern Class Ref.1=nullable text, Ext Pattern Class Ref.2=nullable text, Ext Pattern Class Ref.3=nullable text, Ext Pattern Class Ref.4=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Extension Pattern", "Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4", "Index"}, {"Extension Pattern", "Ext Pattern Class Ref.1", "Ext Pattern Class Ref.2", "Ext Pattern Class Ref.3", "Ext Pattern Class Ref.4", "Index"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Expanded Custom", {"Extension ID", "Extension Pattern", "Index"}, "Attribute", "Value"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Changed Type2",{"Attribute.1"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns1", "Custom", each if [Attribute.2]=[Index] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom] = 1)),
    #"Trimmed Text" = Table.TransformColumns(#"Filtered Rows",{{"Value", Text.Trim, type text}}),
    #"Removed Columns2" = Table.RemoveColumns(#"Trimmed Text",{"Index", "Attribute.2", "Custom"})
in
    #"Removed Columns2"

Before:

vstephenmsft_0-1709194177325.png

 

After:

vstephenmsft_1-1709194185567.png

You can download my latest attachment for more information.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

amustafa
Super User
Super User

Please explain the 'rule' why it should pick "Yellow" over "Green".





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




 

BrendenS_3-1709058703121.png

 

Sure, the exact order of the Extension Pattern column coordinates with the Ext Pattern Class Ref semicolon separated values.  See the screenshot below for a visual example. Note in this example the EXT00002 has three different extension patterns, two green, and one yellow. Other Extension IDs may have more than three extension patterns with differentiating colors in the Ext Pattern Class Ref column. Will include another example.  Thank you for your help!

 

BrendenS_0-1709058113107.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors