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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
colinmaitland
Regular Visitor

Replacer.ReplaceValue / Replacer.ReplaceText

Hi, I am trying to replace null and empty string values in a text data type column named Country with a value from another text data type column named "Country (Parent Organisation)" without changing the data type of the Country column from TEXT to ANY in a single step.

 

(a) Here is my source data …

colinmaitland_0-1649809246079.png

 

(b) This is what I get when I use Replacer.ReplaceValue … i.e., the Country column data type is now ANY rather than TEXT.

 

 #"Replace Value" =
        Table.ReplaceValue(#"Previous Step",
            each [Country],
            each if [Country] = null or Text.Trim([Country]) = "" then Text.Trim([#"Country (Parent Organisation)"]) else Text.Trim([Country]),
            Replacer.ReplaceValue,
            {"Country"}
        )

 

 

colinmaitland_2-1649809246082.png

 

(c) This is what I get when I use Replacer.ReplaceText … It is not replaceing the empty text values and of course it is not replacing the null values because null is not a text data type.

 

#"Replace Value" =
        Table.ReplaceValue(#"Previous Step",
            each [Country],
            each if [Country] = null or Text.Trim([Country]) = "" then Text.Trim([#"Country (Parent Organisation)"]) else Text.Trim([Country]),
            Replacer.ReplaceText,
            {"Country"}
        )

 

 

colinmaitland_4-1649809246083.png

 

(d) This is what I get when I wrap the Replacer.ReplaceValues version in a Table.TransformColumnTypes step …

 

#"Replace Value" =
        Table.TransformColumnTypes(
            Table.ReplaceValue(#"Previous Step",
                each [Country],
                each if [Country] = null or Text.Trim([Country]) = "" then Text.Trim([#"Country (Parent Organisation)"]) else Text.Trim([Country]),
                Replacer.ReplaceValue,
                {"Country"}
            ),
            {{"Country", type text}}
        )

 

 

colinmaitland_6-1649809246085.png

 

But is there a way to use Replacer.ReplaceText, or some other more straightforward way, to achieve this result in a single step?

Many thanks.

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Although I'm not at my computer and cannot offer you a proper technical solution, in situations like this with Power Query I would just do each of the individual steps--that is, replace the nulls, with the GUI function,  replace the blanks with the GUI function, and I mean replace them by right clicking on the value and then selecting Replace value, that way you get the correct technical steps that you can just cobble together into the if-then-else statement.

 

--Nate

View solution in original post

Hi Nate

Using your approach, the following works perfectly, including handling the fact that the last row has null for both Country and Country (Parent Organisation). It does, however, require more nested business logic than (d) in my original post, and also uses a mixture of Replacer.ReplaceValue and Replacer.ReplaceText, but it has been a useful exercise to explore this.

    #"Replace Value" =
        Table.ReplaceValue(
            Table.ReplaceValue(
                Table.ReplaceValue(
                    Table.ReplaceValue(
                        #"Previous Step", null, "X", Replacer.ReplaceValue, {"Country"}
                    ),
                    "", "X", Replacer.ReplaceValue, {"Country"}
                ),
                each [Country],
                each if Text.Trim([Country]) = "X"
                    then [#"Country (Parent Organisation)"]
                    else [Country],
                Replacer.ReplaceText,
                {"Country"}
            ),
            "X", null, Replacer.ReplaceValue, {"Country"}
        )

Here is the result ...

colinmaitland_0-1649887677541.png

Many thanks
Colin

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Although I'm not at my computer and cannot offer you a proper technical solution, in situations like this with Power Query I would just do each of the individual steps--that is, replace the nulls, with the GUI function,  replace the blanks with the GUI function, and I mean replace them by right clicking on the value and then selecting Replace value, that way you get the correct technical steps that you can just cobble together into the if-then-else statement.

 

--Nate

Hi Nate

Using your approach, the following works perfectly, including handling the fact that the last row has null for both Country and Country (Parent Organisation). It does, however, require more nested business logic than (d) in my original post, and also uses a mixture of Replacer.ReplaceValue and Replacer.ReplaceText, but it has been a useful exercise to explore this.

    #"Replace Value" =
        Table.ReplaceValue(
            Table.ReplaceValue(
                Table.ReplaceValue(
                    Table.ReplaceValue(
                        #"Previous Step", null, "X", Replacer.ReplaceValue, {"Country"}
                    ),
                    "", "X", Replacer.ReplaceValue, {"Country"}
                ),
                each [Country],
                each if Text.Trim([Country]) = "X"
                    then [#"Country (Parent Organisation)"]
                    else [Country],
                Replacer.ReplaceText,
                {"Country"}
            ),
            "X", null, Replacer.ReplaceValue, {"Country"}
        )

Here is the result ...

colinmaitland_0-1649887677541.png

Many thanks
Colin

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors