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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jorr13
Frequent Visitor

How would I replace individual zeros in Power Query Editor but not if a number included a zero

How would I replace individual zeros with blanks but leave zeros if it was contained within say a phone number?

 

Want to replace 0 with nothing/blank but when I use the repalce values function in power Query Editor, where a number set includes a 0, I do not want it to remove the zero.

 

If I used the funtion on say 3204920938 it would change to 32492938. I would want it to stay the same in this case but only make the field blank if it was "0".

1 ACCEPTED SOLUTION

@Jorr13,

 

Try this Power Query step:

 

ReplaceText = Table.ReplaceValue(
    Source,
    each if [Column1] = "0" then null else "0",
    each if [Column1] = "0" then [Column1] else "",
    Replacer.ReplaceText,
    {"Column1"}
  )




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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @Jorr13 , 

Please refer to my pbix file to see if it helps you.

= Table.ReplaceValue(Source,"0","",Replacer.ReplaceValue,{"Column1"})

vpollymsft_0-1649918864014.png

If I have misunderstood your meaning, please provide your pbix file without privacy information and your desired output.

 

Best Regards

Community Support Team _ Polly

 

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

 

DataInsights
Super User
Super User

@Jorr13,

 

In Power Query, create a custom column using this if statement. This assumes [Column1] is a text data type.

 

if [Column1] <> "0" then Text.Replace([Column1], "0", "") else [Column1]

 

DataInsights_0-1649775701580.png

 





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

Proud to be a Super User!




Thanks @DataInsights Do you know if there is a way to do the replacement without creating a new column?

@Jorr13,

 

Try this Power Query step:

 

ReplaceText = Table.ReplaceValue(
    Source,
    each if [Column1] = "0" then null else "0",
    each if [Column1] = "0" then [Column1] else "",
    Replacer.ReplaceText,
    {"Column1"}
  )




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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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