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
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
Super User
Super User

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors