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
petar_kisdobran
Frequent Visitor

Replace value if text contains

Hi,

 

I have a table containing column with date and g/l account code and need to have these in separate columns.

 

Columns are duplicated, however I do not know how to replace all values eg with text ending "-2022" with blank, can you please help me?

 

petar_kisdobran_0-1666865883080.png

 

Thank you!

 

My best,

Petar

2 ACCEPTED SOLUTIONS
mussaenda
Super User
Super User

Hi @petar_kisdobran ,

 

Try this.

Create a blank query,

Open Advanced Editor,

Select All,

Paste this code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjBR0FXwTUzOyMxLLVZIzEtRyMwrLknMyUksyczPK1aK1YlWAhMGlroGZrpGBkZGCDGIhImRAdCMkKLEvOKC/KISsCG5qUCeQn6aQglMGE0XVKsxSKtLakFRanIm2EYUPQSNMjbUNTBEOAqZGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account name" = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,each [Account name], each if Text.Contains([Account name], "-2022") then "" else [Account name], Replacer.ReplaceText,{"Account name"})
in
    #"Replaced Value"

 

Basically the answer is coming from a previous post.

Link is Replace based on condition 

 

Hope this helps

 

mussaenda_0-1666872825500.png

 

View solution in original post

Hi @petar_kisdobran,

 

In that case, it will be like:

Source = Excel.Workbook(Web.Contents("https://XYZ.xlsx"), null, true),
Data_Sheet = Source{[Item="Data",Kind="Sheet"]}[Data],
#"Replaced Value" = Table.ReplaceValue(Data_Sheet,each [Account name], each if Text.Contains([Account name], "-2022") then "" else [Account name], Replacer.ReplaceText,{"Account name"})
in
    #"Replaced Value"

View solution in original post

3 REPLIES 3
mussaenda
Super User
Super User

Hi @petar_kisdobran ,

 

Try this.

Create a blank query,

Open Advanced Editor,

Select All,

Paste this code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjBR0FXwTUzOyMxLLVZIzEtRyMwrLknMyUksyczPK1aK1YlWAhMGlroGZrpGBkZGCDGIhImRAdCMkKLEvOKC/KISsCG5qUCeQn6aQglMGE0XVKsxSKtLakFRanIm2EYUPQSNMjbUNTBEOAqZGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account name" = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,each [Account name], each if Text.Contains([Account name], "-2022") then "" else [Account name], Replacer.ReplaceText,{"Account name"})
in
    #"Replaced Value"

 

Basically the answer is coming from a previous post.

Link is Replace based on condition 

 

Hope this helps

 

mussaenda_0-1666872825500.png

 

Hi Mussaenda,

 

Thanks for quick response.

 

Unfortunately i am not knowledgable enought to apply it to my source of data.

 

Also, not sure how to share the Excel file here, if possible please let me know or if you could rewrite the script with this source of data

 

Source = Excel.Workbook(Web.Contents("https://XYZ.xlsx"), null, true),
Data_Sheet = Source{[Item="Data",Kind="Sheet"]}[Data],

Thanks!

 

My best,

Petar

Hi @petar_kisdobran,

 

In that case, it will be like:

Source = Excel.Workbook(Web.Contents("https://XYZ.xlsx"), null, true),
Data_Sheet = Source{[Item="Data",Kind="Sheet"]}[Data],
#"Replaced Value" = Table.ReplaceValue(Data_Sheet,each [Account name], each if Text.Contains([Account name], "-2022") then "" else [Account name], Replacer.ReplaceText,{"Account name"})
in
    #"Replaced Value"

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