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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Maviso69
New Member

Power Query TextJoin

I import a sorted two column list in power query.

Column A contains the product codes
Coumn B contains a category that the product code belongs to.

A given product code will belong to several categories and therefore will appear on a number of rows - each time against a category.

I wuold like to transfom this a follows:

Column A (doesn't have to be) contains a row for each unique product code.
Column B (doesn't have to be) now contains a comma / pipe seperated entry containing all the categories that the product belongs to.

Can this be done? - Yes you guessed I'm a Newbie.

Malcolm

1 ACCEPTED SOLUTION

@Maviso69 You need to go to advanced editor and then use the GroupedRows step/code, I have uploaded the file here https://drive.google.com/file/d/1M6ULVsU3m_IJc08CupGCwbJXCcVyGPDe/view?usp=share_link to give you an idea.

View solution in original post

5 REPLIES 5
Maviso69
New Member

Wow! - way beyond my programming ability at this point so will happily cut & paste to try. Intersting that your code doesn't appear to require "Column A" to be sorted either. Will try in the morning now. Many thanks

AntrikshSharma
Community Champion
Community Champion

@Maviso69 Create a new blank query in Power Query UI then go to Advanced Editor and paste this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIsKMhJVYrViVZyAvJ8E/PS88E8ZxQeSKVTYh4Q4lAakJpYBFfpnJFaVFQJVxmeWJJalJuak5+HpjwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Category = _t]),
    ChangedType = 
        Table.TransformColumnTypes ( 
            Source, 
            { 
                { "Code", type text }, 
                { "Category", type text }
            }
        ),
    GroupedRows = 
        Table.Group ( 
            ChangedType, 
            {"Code"}, 
            {
                {
                    "Result", 
                    each 
                        Text.Combine ( 
                            List.Distinct ( _[Category] ), 
                            ", " 
                        ), 
                    type text
                }
            }
        )
in
    GroupedRows

AntrikshSharma_0-1668081238565.png

 

Apologies for my naivity but trying this out "as is" prom

I'm guessing this part needs to be edited by me according to my system? My "source" is "Table1".....

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIsKMhJVYrViVZyAvJ8E/PS88E8ZxQeSKVTYh4Q4lAakJpYBFfpnJFaVFQJVxmeWJJalJuak5+HpjwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Category = _t]),
ChangedType =
Table.TransformColumnTypes (
Source,
{
{ "Code", type text },
{ "Category", type text }
}
),

result Error message - "Eof expected"

 

Further advice would be appreciated - Malcoln

@Maviso69 You need to go to advanced editor and then use the GroupedRows step/code, I have uploaded the file here https://drive.google.com/file/d/1M6ULVsU3m_IJc08CupGCwbJXCcVyGPDe/view?usp=share_link to give you an idea.

Many thanks - much appreciated.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.