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
cristianml
Post Prodigy
Post Prodigy

Replace values/Strings from a Column in query editor

Hi,

 

I need help with the following in query editor. It gives an error:

 

cristianml_0-1651780865916.png

 

I'm trying to replace IF those values/strings are in each row from from the COLUMN1

 

Could you please help me to fix the error ? 

= Table.ReplaceValue(#"Replaced Value1",
each if "String1" in [COLUMN1] then "01",
else if "String2" in [COLUMN1] then "02",
else if "String3" in [COLUMN1] then "03",
else if "String4" in [COLUMN1] then "04",
else if "String5" in [COLUMN1] then "05",
else if "String6" in [COLUMN1] then "06",
else if "String7" in [COLUMN1] then "07",
else "NADA"),Replacer.ReplaceText,{"COLUMN1"})

 

 

The string is NOT equal the cell but inside a bunch of words so need to replace only that string:

Meaning:  XXXXXXString1XXX     > replace with >   XXXXXX01XXX

 

Thanks

1 ACCEPTED SOLUTION

Hi @cristianml ,

 

Now I see where you wanna get to! 🙂 This one right?

tomfox_0-1651863959637.png

 



Try this:

Table.ReplaceValue(#"Changed Type", each [COLUMN1], 
each if Text.Contains([COLUMN1], "January") then Text.Replace([Custom], "January", "01")
else if Text.Contains([COLUMN1], "February") then Text.Replace([Custom], "February", "02")
else if Text.Contains([COLUMN1], "March") then Text.Replace([Custom], "March", "03")
else if Text.Contains([COLUMN1], "April") then Text.Replace([Custom], "April", "04")
else if Text.Contains([COLUMN1], "May") then Text.Replace([Custom], "May", "05")
else if Text.Contains([COLUMN1], "June") then Text.Replace([Custom], "June", "06")
else if Text.Contains([COLUMN1], "July") then Text.Replace([Custom], "July", "07")
else "NADA", Replacer.ReplaceText,{"COLUMN1"})

 

Is this the solution? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

7 REPLIES 7
tackytechtom
Super User
Super User

Hi @cristianml ,

 

Spontaneously, I could think of that you might have forgotten to change the the source of the next step. But that is just a wild guess. Do you have the possibility to upload the file or alternatively, upload the data and the Power Query M code?

 

thanks!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @cristianml ,

 

Does it work with the following code?

= Table.ReplaceValue(#"Replaced Value1", "Custom",
each if Text.Contains([COLUMN1], "String1") then "01"
else if Text.Contains([COLUMN1], "String2") then "02"
else if Text.Contains([COLUMN1], "String3") then "03"
else if Text.Contains([COLUMN1], "String4") then "04"
else if Text.Contains([COLUMN1], "String5") then "05"
else if Text.Contains([COLUMN1], "String6") then "06"
else if Text.Contains([COLUMN1], "String7") then "07"
else "NADA", Replacer.ReplaceText,{"COLUMN1"})

 

Let me know if this fixes the issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi @tackytechtom ,

 

Seems ok with no error but is not replacing anything : See below :

PHOTO.png

could you identify why is not working ?

Hi @cristianml 

 

My bad, I forgot to specify the column where all this should happen.... Can you try this? 🙂

= Table.ReplaceValue(#"Changed Type", each [COLUMN1], each if Text.Contains([COLUMN1], "January") then "01"
else if Text.Contains([COLUMN1], "February") then "02"
else if Text.Contains([COLUMN1], "March") then "03"
else if Text.Contains([COLUMN1], "April") then "04"
else if Text.Contains([COLUMN1], "May") then "05"
else if Text.Contains([COLUMN1], "June") then "06"
else if Text.Contains([COLUMN1], "July") then "07"
else "NADA", Replacer.ReplaceText,{"COLUMN1"})

 

Let me know! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi @tackytechtom ,

 

Almost there. I don't understand why it changes all instead of only the string:

cristianml_0-1651861296306.png

 

I need to keep the rest of the string/text:

cristianml_1-1651861478090.png

 

Is there somenting that we can change in the last formula to keep that ?

 

 

 

Hi @cristianml ,

 

Now I see where you wanna get to! 🙂 This one right?

tomfox_0-1651863959637.png

 



Try this:

Table.ReplaceValue(#"Changed Type", each [COLUMN1], 
each if Text.Contains([COLUMN1], "January") then Text.Replace([Custom], "January", "01")
else if Text.Contains([COLUMN1], "February") then Text.Replace([Custom], "February", "02")
else if Text.Contains([COLUMN1], "March") then Text.Replace([Custom], "March", "03")
else if Text.Contains([COLUMN1], "April") then Text.Replace([Custom], "April", "04")
else if Text.Contains([COLUMN1], "May") then Text.Replace([Custom], "May", "05")
else if Text.Contains([COLUMN1], "June") then Text.Replace([Custom], "June", "06")
else if Text.Contains([COLUMN1], "July") then Text.Replace([Custom], "July", "07")
else "NADA", Replacer.ReplaceText,{"COLUMN1"})

 

Is this the solution? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

hI @tackytechtom ,

 

Thanks !Finally I solved it. I Changed  Text.Replace([Custom]  with Text.Replace([COLUMN1]

 

cristianml_0-1652031317674.png

 

Thank you !:)

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.