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
Anonymous
Not applicable

Replace values

Hi, 
I have two columns - countries and target. I want to change target to 1 if the country column include name of specific countries.
Look at the example. In this example I want to change Target to 1 for Italy and France. Is it possible to do this without creating additional column?

CountryTraget
23456France3
3456Italy4
98765Spain5
45678Greece7
9872France4
098France7
0834Germany4
0987Italy9
34567Italy8
9876Spain0
3468098Spain5
23098Spain4
9798Poland7


Thanks for help,
Aleks

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi Aleks,

 

Select your [Traget] column, right-click on the column header and select 'Replace Values'.

In the dialog, enter any number to find and to replace with and hit ok. I chose to find 9999 and replace with 1111, so the code produced in the formula bar looks like this:

BA_Pete_0-1680602894335.png

 

Now you can edit the code to make the search dynamic by changing it to this:

BA_Pete_1-1680603070790.png

 

Full example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY69DsIwDAbfxXOHKH92XoCKDYkx6mBBBqQSUMTStyckjVXW0332xQjaWOdPhfMtwQQGlinCD50/vG6V2EYCoXfXNz9yRa6h6iDNJaU2xKFpudWXKpCQLikydk7lyXk7Wjg+BmkQRBIxGtQuearT/zBtDmjPx0CX18r53iuWLw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Traget = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Traget", Int64.Type}}),

    repValue = Table.ReplaceValue(chgTypes, each [Traget], each if Text.Contains([Country], "Italy") or Text.Contains([Country], "France") then 1 else [Traget], Replacer.ReplaceValue, {"Traget"})

in
    repValue

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi Aleks,

 

Select your [Traget] column, right-click on the column header and select 'Replace Values'.

In the dialog, enter any number to find and to replace with and hit ok. I chose to find 9999 and replace with 1111, so the code produced in the formula bar looks like this:

BA_Pete_0-1680602894335.png

 

Now you can edit the code to make the search dynamic by changing it to this:

BA_Pete_1-1680603070790.png

 

Full example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY69DsIwDAbfxXOHKH92XoCKDYkx6mBBBqQSUMTStyckjVXW0332xQjaWOdPhfMtwQQGlinCD50/vG6V2EYCoXfXNz9yRa6h6iDNJaU2xKFpudWXKpCQLikydk7lyXk7Wjg+BmkQRBIxGtQuearT/zBtDmjPx0CX18r53iuWLw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Traget = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Traget", Int64.Type}}),

    repValue = Table.ReplaceValue(chgTypes, each [Traget], each if Text.Contains([Country], "Italy") or Text.Contains([Country], "France") then 1 else [Traget], Replacer.ReplaceValue, {"Traget"})

in
    repValue

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.