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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Replacing nulls or empty strings doesn't always work - what am i doing wrong?

If i want to replace several values in one step including any nulls/empty strings my mcode seems to skip these nulls/empty strings.

 

example:

= Table.ReplaceValue(#"Previous Step", each [mycolumn], each

if [mycolumn] = "x" then "Yes" else

if [mycolumn] = ""  then "Unknown" else

if [mycolumn] is null  then "Unknown" else

"No" , Replacer.ReplaceText,{"mycolumn"})

 

the above leaves me with "Yes", "No" and (blank)

 

What am I doing wrong?

 

 

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Anonymous - I understand what you are trying to achieve but I am not a fan of Table.ReplaceValue.  I prefer the Table.TransformColumns approach  Check the last paragraph in Section 3. 

 

The formula would look like this:

= Table.TransformColumns(#"Previous Step", 
 { 
  { "mycolumn", each 
      if _ = "x" then "Yes" 
      else if _ = ""  then "Unknown" 
      else if _ = null then "Unknown" 
      else "No" , type text
  }
 }
)
 

View solution in original post

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

May I know could my solution solve your problem? If so, would you mind accept it as solution? More people who have the same requirment will find the solution quickly and benefit here, thank you!

 

Best Regards,
Community Support Team _ kalyj

v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

You should replace the Replacer.ReplaceText in the code with Replacer.ReplaceValue.

Result:

vkalyjmsft_3-1668756434025.png

                              vkalyjmsft_4-1668756585590.png

vkalyjmsft_2-1668756385222.png

Best Regards,
Community Support Team _ kalyj

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

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Anonymous - I understand what you are trying to achieve but I am not a fan of Table.ReplaceValue.  I prefer the Table.TransformColumns approach  Check the last paragraph in Section 3. 

 

The formula would look like this:

= Table.TransformColumns(#"Previous Step", 
 { 
  { "mycolumn", each 
      if _ = "x" then "Yes" 
      else if _ = ""  then "Unknown" 
      else if _ = null then "Unknown" 
      else "No" , type text
  }
 }
)
 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.