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

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

Reply
Anonymous
Not applicable

How to replace cell text of a column based on cell text of another column

I have two columns called "shipping_state" and "shipping_city".

 

If shipping_state has blanks, I want Power Query to cross check what is the text value in the same row under shipping_city and for example, if shipping_city has text of "Newark", it will replace the value of shipping_state with "New Jersey. This is my code, there are no syntax errors or running errors, but it does not give me the output on the shipping_state column. Appreicate if someone can help me out!

 

#"Replace States" = Table.ReplaceValue(#"Filtered Rows2", each if [shipping_state] = "" then
        if [shipping_city] = "Newark" then "New Jersey"
        else if [shipping_city] = "Stamford" then "Connecticut"
        else [shipping_state]
    else [shipping_state],
    each [shipping_state],
    Replacer.ReplaceValue,
    {"shipping_state"}
)
in
    #"Replace States"

 

 

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

@Anonymous 

    replacements = 
        [Newark = "New Jersey", 
        Stamford = "Connecticut"],
    #"Replace States" = Table.ReplaceValue(
        #"Filtered Rows2",
        "", each Record.FieldOrDefault(replacements, [shipping_city], null),
        (v, o, n) => if v = "" then n else v,
        {"shipping_state"}
    )
in
    #"Replace States"

View solution in original post

1 REPLY 1
AlienSx
Super User
Super User

@Anonymous 

    replacements = 
        [Newark = "New Jersey", 
        Stamford = "Connecticut"],
    #"Replace States" = Table.ReplaceValue(
        #"Filtered Rows2",
        "", each Record.FieldOrDefault(replacements, [shipping_city], null),
        (v, o, n) => if v = "" then n else v,
        {"shipping_state"}
    )
in
    #"Replace States"

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Kudoed Authors