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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ACraig08
Helper I
Helper I

Transform a columns values to a list (like a structured column)

So, I have a column like this in Table A:

Codes
611710, 541611, 541720
541310
314999
541810, 541430, 541613
541611

I have a list called "Interested Codes"

List
541310
541613
541611
541890

 

I am trying to add a column to Table A that identifies if each cell contains a value from the Interested Codes list. So, in the end it would be like this:

CodesInterested In
611710, 541611, 541720true
541310true
314999false
541810, 541430false
541611true

 

I was using the List.ContainsAny({[Codes]},#"Interested Codes")

but it only works when there is a single value in the Codes cell. 

 

My question is, is there a way to make it so the values in the Codes column are individual lists like if it were a structured column like below so that I can use the formula above.

Codes
List
List
List
List
List

 

Or is there a better way to handle this.

 

Thank you for your help.

1 ACCEPTED SOLUTION
vicky_
Super User
Super User

I would try a different way:

Add an index (so that i know which codes belong together), and then split and pivot the table so that i end up with this:

vicky__0-1716503930697.png

vicky__1-1716503955528.png

 Then merge the queries to find which codes are in the list

vicky__3-1716504698573.png

And finally combine it all back together with the GroupBy 

vicky__4-1716504792118.png

BTW, this will require some small modifications to the default formulas. The M-Code is below for reference. Also, after splitting, you'll want your Codes to be of type Text so that you don't get thrown an error in the Grouping step.

let
    Source = // your source here
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codes", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index", "Codes", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Codes.1", "Codes.2", "Codes.3"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Index"}, "Attribute", "Value"),
    #"Trimmed Text" = Table.TransformColumns(#"Unpivoted Columns",{{"Value", Text.Trim, type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Trimmed Text",{"Attribute"}),
    #"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Value"}, #"Interested List", {"List"}, "Interested List", JoinKind.LeftOuter),
    #"Aggregated Interested List" = Table.AggregateTableColumn(#"Merged Queries", "Interested List", {{"List", List.NonNullCount, "Code In List"}}),
    #"Grouped Rows" = Table.Group(#"Aggregated Interested List", {"Index"}, {{"Values", each Text.Combine([Value], ", "), type text}, {"Code in List", each List.Max([Code In List]), type number}})
in
    #"Grouped Rows"

 

View solution in original post

1 REPLY 1
vicky_
Super User
Super User

I would try a different way:

Add an index (so that i know which codes belong together), and then split and pivot the table so that i end up with this:

vicky__0-1716503930697.png

vicky__1-1716503955528.png

 Then merge the queries to find which codes are in the list

vicky__3-1716504698573.png

And finally combine it all back together with the GroupBy 

vicky__4-1716504792118.png

BTW, this will require some small modifications to the default formulas. The M-Code is below for reference. Also, after splitting, you'll want your Codes to be of type Text so that you don't get thrown an error in the Grouping step.

let
    Source = // your source here
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codes", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index", "Codes", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Codes.1", "Codes.2", "Codes.3"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Index"}, "Attribute", "Value"),
    #"Trimmed Text" = Table.TransformColumns(#"Unpivoted Columns",{{"Value", Text.Trim, type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Trimmed Text",{"Attribute"}),
    #"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Value"}, #"Interested List", {"List"}, "Interested List", JoinKind.LeftOuter),
    #"Aggregated Interested List" = Table.AggregateTableColumn(#"Merged Queries", "Interested List", {{"List", List.NonNullCount, "Code In List"}}),
    #"Grouped Rows" = Table.Group(#"Aggregated Interested List", {"Index"}, {{"Values", each Text.Combine([Value], ", "), type text}, {"Code in List", each List.Max([Code In List]), type number}})
in
    #"Grouped Rows"

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.