cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Nilson
Frequent Visitor

Match values in comma seperated column

Hello,
 
I have a question regarding comma seperated values.
 
The example data consists out of three columns: "Product_ID" (unique identifier), "Parts_Used" (comma sperated list) and "Price" (simple number).
 
As you can see in the "Matching"-table I'd like to be able to change the part names by updating the corresponding names within this table. The problem is that I want to keep the comma seperated form of the "Parts_Used" column.
 
Is this somehow possible?

 

Here you can find the sample file:

LINK 

 

 

Kind regards

Nilso

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Match values in comma seperated column

Hi @Nilson , 

You could try to use M code to achieve this goal. You could refer to my sample for details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY9LCoAwDAWvIll30XzVW7gvRbyCeH+MrSmIu0dnmpeUAggJtuO89oxp6oEjmDMkFqipAA2RgmuExZl72kT+TcT4gU8bslATZYhrDJr9SYU718FHkX0b39UsRMpRFDfg2m5Qg1pv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Product_ID = _t, Parts_Used = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product_ID", Int64.Type}, {"Parts_Used", type text}, {"Price", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Parts_Used], ",")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Custom"," ","",Replacer.ReplaceText,{"Custom"}),
    #"Merged Queries" = Table.NestedJoin(#"Replaced Value", {"Custom"}, #"Table (2)", {"Part_Old"}, "Table (2)", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Part_New"}, {"Part_New"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table (2)",{"Parts_Used", "Custom"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Product_ID"}, {{"Part_new", each Text.Combine([Part_New], ","), type text}, {"Price", each List.Average([Price]), type number}})
in
    #"Grouped Rows"

Best Regards,
Zoe Zhi

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

3 REPLIES 3
Community Support
Community Support

Re: Match values in comma seperated column

Hi @Nilson , 

It seems that you upload wrong sample, I didn't see "Product_ID" (unique identifier), "Parts_Used" (comma sperated list) and "Price" (simple number) in your link. So if possible could you please inform me more detailed information(such as your expected output and your sample data)? Then I will help you more correctly.

Please do mask sensitive data before uploading.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

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

Nilson
Frequent Visitor

Re: Match values in comma seperated column

I'm sorry, this was my mistake!

 

LINK 

 

Thank you 🙂

Community Support
Community Support

Re: Match values in comma seperated column

Hi @Nilson , 

You could try to use M code to achieve this goal. You could refer to my sample for details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY9LCoAwDAWvIll30XzVW7gvRbyCeH+MrSmIu0dnmpeUAggJtuO89oxp6oEjmDMkFqipAA2RgmuExZl72kT+TcT4gU8bslATZYhrDJr9SYU718FHkX0b39UsRMpRFDfg2m5Qg1pv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Product_ID = _t, Parts_Used = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product_ID", Int64.Type}, {"Parts_Used", type text}, {"Price", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Parts_Used], ",")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Custom"," ","",Replacer.ReplaceText,{"Custom"}),
    #"Merged Queries" = Table.NestedJoin(#"Replaced Value", {"Custom"}, #"Table (2)", {"Part_Old"}, "Table (2)", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Part_New"}, {"Part_New"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table (2)",{"Parts_Used", "Custom"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Product_ID"}, {{"Part_new", each Text.Combine([Part_New], ","), type text}, {"Price", each List.Average([Price]), type number}})
in
    #"Grouped Rows"

Best Regards,
Zoe Zhi

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

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors