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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

replace a value within text but only between square brackets

Hi I've got some data as follows (in one column):

"third_party_funded": "Yes", "risk_score": 5.4, "tender_assurance_rating": "Amber/Green", "project_number": ["8675309", "771595", "107140"],...

 

It's comma delimited and in a later step I will be splitting each key value pair into columns however as you can see, there is a list in one of the KV pairs (Project Number), I would like to replace the commas in between the square brackets so that in my later step, they are not split.

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 
Please add the following custom column where I replace the "," with "|" within the [...]

let T=Text.BetweenDelimiters(_[Data], "[", "]") in Text.Replace( _[Data],T, Text.Replace(T,",","|" ))


Orginal Text:

Fowmy_0-1661941455037.png

|
Result:

Fowmy_1-1661941469854.png


Full Code:
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcxBDsIgFATQqzR/bRRiEdudK89ggBCEr6KRNh9YeHtL2E1mXkYpKK9Iwa6Oys8+agoY5kHDDbOG3RYo5o/NfiHUMA9iP7ay4ObIupwrueTRkisxPZvQcPnekQ5XQkz9YqXljb7YVNvSkNJwPklxZFMXUnIxiZ45k3xkGgwY8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let T=Text.BetweenDelimiters(_[Data], "[", "]") in Text.Replace( _[Data],T, Text.Replace(T,",","|" )))
in
    #"Added Custom"



 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@Anonymous 
Please add the following custom column where I replace the "," with "|" within the [...]

let T=Text.BetweenDelimiters(_[Data], "[", "]") in Text.Replace( _[Data],T, Text.Replace(T,",","|" ))


Orginal Text:

Fowmy_0-1661941455037.png

|
Result:

Fowmy_1-1661941469854.png


Full Code:
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcxBDsIgFATQqzR/bRRiEdudK89ggBCEr6KRNh9YeHtL2E1mXkYpKK9Iwa6Oys8+agoY5kHDDbOG3RYo5o/NfiHUMA9iP7ay4ObIupwrueTRkisxPZvQcPnekQ5XQkz9YqXljb7YVNvSkNJwPklxZFMXUnIxiZ45k3xkGgwY8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let T=Text.BetweenDelimiters(_[Data], "[", "]") in Text.Replace( _[Data],T, Text.Replace(T,",","|" )))
in
    #"Added Custom"



 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

You absolute legend!

Thanks that worked perfectly!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors