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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
goodhvnting
Frequent Visitor

Replace value based on condition from other column

Hello! 

 

I've searched this forum to try to find a solution to my problem but haven't quite gotten there yet so I am reaching out to the community. 

 

I am trying to replace a value in a column based on a condition from another column. I can't do this by creating a conditional column because there are hundreds of values and it would take too long for me to specify for each one when really I only want to change one value. 

 

This is the statement I have so far but it is not achieving my desired result: 

= Table.ReplaceValue(#"Reordered Columns", each [Campground_Name],each if [PARK_ID] = "88" then "Chain Lakes South" else [Campground_Name], Replacer.ReplaceValue,{"CAMPGROUND_NAME"})

 

Basically, what I want is for every time [Park_ID] = 88 then change [Campground_Name] to "Chain Lakes South". 

 

Any help would be greatly appreciated 🙂 

 

 

3 ACCEPTED SOLUTIONS
bharath_v
Resolver I
Resolver I

Hi @goodhvnting 

 

I believe you can still use conditional column to define one value and use "Else" clause for rest of the values.

I tried to simulate your scenario, let me know if this helps!

Input:

bharath_v_1-1677799276334.png

 

Conditional Column:

bharath_v_0-1677799224768.png

Output:

bharath_v_2-1677799319923.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Cheers.

View solution in original post

bolfri
Super User
Super User

You almost did it. 🙂

 

= Table.ReplaceValue(
                #"Changed Type",
                each if [PARK_ID] = 88 then [Campground_Name] else false,
                each "Chain Lakes South",
                Replacer.ReplaceValue,
                {"Campground_Name"}
            )

 

Before:

bolfri_0-1677799333930.png

After:

bolfri_1-1677799344239.png

Full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrOz01VyM9JUSguKU1LU4rViVYywi5sjF3YwgK7uKUlCepjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PARK_ID = _t, Campground_Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PARK_ID", Int64.Type}, {"Campground_Name", type text}}),
    #"Replaced Value" 
        = Table.ReplaceValue(
                #"Changed Type",
                each if [PARK_ID] = 88 then [Campground_Name] else false,
                each "Chain Lakes South",
                Replacer.ReplaceValue,
                {"Campground_Name"}
            )
in
    #"Replaced Value"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

This worked perfectly. Thank you so much! I knew I was close but wouldn't have been able to get there without the help. 

 

Cheers! 

View solution in original post

4 REPLIES 4
bolfri
Super User
Super User

You almost did it. 🙂

 

= Table.ReplaceValue(
                #"Changed Type",
                each if [PARK_ID] = 88 then [Campground_Name] else false,
                each "Chain Lakes South",
                Replacer.ReplaceValue,
                {"Campground_Name"}
            )

 

Before:

bolfri_0-1677799333930.png

After:

bolfri_1-1677799344239.png

Full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrOz01VyM9JUSguKU1LU4rViVYywi5sjF3YwgK7uKUlCepjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PARK_ID = _t, Campground_Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PARK_ID", Int64.Type}, {"Campground_Name", type text}}),
    #"Replaced Value" 
        = Table.ReplaceValue(
                #"Changed Type",
                each if [PARK_ID] = 88 then [Campground_Name] else false,
                each "Chain Lakes South",
                Replacer.ReplaceValue,
                {"Campground_Name"}
            )
in
    #"Replaced Value"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This worked perfectly. Thank you so much! I knew I was close but wouldn't have been able to get there without the help. 

 

Cheers! 

bharath_v
Resolver I
Resolver I

Hi @goodhvnting 

 

I believe you can still use conditional column to define one value and use "Else" clause for rest of the values.

I tried to simulate your scenario, let me know if this helps!

Input:

bharath_v_1-1677799276334.png

 

Conditional Column:

bharath_v_0-1677799224768.png

Output:

bharath_v_2-1677799319923.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Cheers.

This worked as well! Thank you! 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.