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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
user180618
Helper I
Helper I

Table.SelectRows when one column concatenated and the other is split into rows

I want to create a custom column using Table.SelectRows (or any other expression) that does the following. In my Table1, I have a column called Cities that lists values separated by a comma:

 

CountryCities
FranceParis, Lyon, Marseille
GermanyBerlin, Munich, Dortmund

 

In my Table2, I have a Sister_Cities column like this:

 

CitySister_Cities
ParisRome
LyonBirmingham
LyonGuangzhou
LyonMontreal
Lyon

Addis Ababa

Marseille

Genoa

Marseille

Glasgow

 

I know the logical thing to do would be to split the first table into rows and then do a join based on the Cities and City columns, but I want to keep them concatenated so that I have a new column in Table1 that looks like this:

 

CountryCitiesCustom.Sister_Cities
FranceParis, Lyon, MarseilleRome, Birmingham, Guangzhou, Montreal, Addis Ababa, Genoa, Glasgow

 

What's the best way to achieve this? Appreciate any advice!

2 REPLIES 2
wdx223_Daniel
Community Champion
Community Champion

NewStep=let a=Table.Group(Table2,"City",{"n",each [Sister_Cities]}) in Table.TransformColumns(Table1,{"Cities",each Text.Combine({_}&List.TransformMany(Text.Split(_,","),each a{[City=_]}?[n]? ??{},(x,y)=>y),",")})

This gives a "Expression.Error: A cyclic reference was encountered during evaluation" error.

 

Here is the full code in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcitKzEtOVdJRCkgsyizWUfCpzM/TUfBNLCpOzczJSVWK1YlWck8tyk3MqwQqckotyskEyZfmZSZn6Ci45BeV5JbmpSjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Cities = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Cities", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "NewStep", each let a=Table.Group(Table2,"City",{"n",each [Sister_Cities]}) in Table.TransformColumns(Table1,{"Cities",each Text.Combine({_}&List.TransformMany(Text.Split(_,","),each a{[City=_]}?[n]? ??{},(x,y)=>y),",")}))
in
    #"Added Custom"

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.