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
LucTP
Helper I
Helper I

Replace values with more text contains

Hi Everyone!

How to Replace values with a text, where some text X contains in column A then Replate Column B values Y else value column A
Example:

 

ADDRESSCOUNTRY
EDIFICIO IBERCONSA-FRIGALSA LA, RIOUXA S/N - TEIS VIGO-PONTEVEDRA, 36216 SPAIN, PT36216 SPAIN
AVDA. EL CHOPO 4, 39311 SANTIAGO DE CARTES, CANTABRIA, SPAIN, ESSPAIN
AVDA. EL CHOPO 4, 39311 SANTIAGO DE CARTES, CANTABRIA, SPAIN, ESSPAIN

 

Result

 

ADDRESSCOUNTRY
EDIFICIO IBERCONSA-FRIGALSA LA, RIOUXA S/N - TEIS VIGO-PONTEVEDRA, 36216 SPAIN, PTSPAIN
AVDA. EL CHOPO 4, 39311 SANTIAGO DE CARTES, CANTABRIA, SPAIN, ESSPAIN
AVDA. EL CHOPO 4, 39311 SANTIAGO DE CARTES, CANTABRIA, SPAIN, ESSPAIN


MY code :  option text X is list not working

 

 

 

Table.ReplaceValue(#"Replaced Value8",each [COUNTRY], each
            if Text.Contains([ADDRESS],{", PT",", ES"}) then "SPAIN" else
                [COUNTRY], Replacer.ReplaceValue, {"COUNTRY"})

 

How to fix it 

 

Thanks & Regards,

LucTP

 

2 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

hello, @LucTP 

    Table.ReplaceValue(
        #"Replaced Value8", 
        each List.Contains(
            {", PT",", ES"},
            [ADDRESS],
            (x, y) => Text.Contains(y, x)
        ),
        null, 
        (v, o, n) => if o then "SPAIN" else v,
        {"COUNTRY"}
    )

View solution in original post

dufoq3
Super User
Super User

Hi @LucTP, anoteher 2 versions of code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tYxBCsIwEEWv8sk6VdJKweWYTutgyIQkBqH0/tcwggsv4OrD4/2374YXWcWLQm6cvcZCw5plo1AIgSyy6PNFKOeIAZWloMmmQ9JYufGSuzLNo5tREkm0SNVY80PMYXdDbaETOMDfNSku/XOdnEOhWIU2xcLwlCsX2zdWumXp4W+SS0/+Kdat2hncOH140EYPIXMcbw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ADDRESS = _t, COUNTRY = _t]),
    ReplaceCountry_v1_Contains = Table.ReplaceValue(Source,
        each List.ContainsAny(Text.SplitAny([ADDRESS], " ,"), {"PT", "ES"}),
        each "SPAIN",
        (x,y,z)=> if y then z else x,
        {"COUNTRY"} ),
    ReplaceCountry_v2_EndsWith = Table.ReplaceValue(Source,
        each List.ContainsAny(List.LastN(Text.SplitAny([ADDRESS], " ,"), 1), {"PT", "ES"}),
        each "SPAIN",
        (x,y,z)=> if y then z else x,
        {"COUNTRY"} )
in
    ReplaceCountry_v2_EndsWith

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @LucTP, anoteher 2 versions of code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tYxBCsIwEEWv8sk6VdJKweWYTutgyIQkBqH0/tcwggsv4OrD4/2374YXWcWLQm6cvcZCw5plo1AIgSyy6PNFKOeIAZWloMmmQ9JYufGSuzLNo5tREkm0SNVY80PMYXdDbaETOMDfNSku/XOdnEOhWIU2xcLwlCsX2zdWumXp4W+SS0/+Kdat2hncOH140EYPIXMcbw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ADDRESS = _t, COUNTRY = _t]),
    ReplaceCountry_v1_Contains = Table.ReplaceValue(Source,
        each List.ContainsAny(Text.SplitAny([ADDRESS], " ,"), {"PT", "ES"}),
        each "SPAIN",
        (x,y,z)=> if y then z else x,
        {"COUNTRY"} ),
    ReplaceCountry_v2_EndsWith = Table.ReplaceValue(Source,
        each List.ContainsAny(List.LastN(Text.SplitAny([ADDRESS], " ,"), 1), {"PT", "ES"}),
        each "SPAIN",
        (x,y,z)=> if y then z else x,
        {"COUNTRY"} )
in
    ReplaceCountry_v2_EndsWith

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

AlienSx
Super User
Super User

hello, @LucTP 

    Table.ReplaceValue(
        #"Replaced Value8", 
        each List.Contains(
            {", PT",", ES"},
            [ADDRESS],
            (x, y) => Text.Contains(y, x)
        ),
        null, 
        (v, o, n) => if o then "SPAIN" else v,
        {"COUNTRY"}
    )

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.