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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
laganlee
Helper II
Helper II

Delete more than one occurrence of a character.

Hi,

All I want to do is remove multiple occurrences of a comma, as you can do with Regex.

I have an input text file which is delimited by commas, in some cases there is more than one,,,,,

for example, my input file may contain two lines:

 

,Price,,,,,,,Quantity,Amount,,,,Tax,,,

,9,,,10,,2,,,,,,,,,,,9,

 

I need to split to columns using delimiter, so I can get the four columns.  Price Quantity Amount Tax

I've done it manually using Replace Values, which is not great.

Some M code would be perfect,,,, but I can't find anything.

(ps I don't want to install Python which would allow me to use Regex)

Many thanks for looking!

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

If you want it in a separate column, use following formula in a custom column (name of the column to be converted is Data)

= Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),",")

If you want in column replacement, issue following statement where Source is the previous step name

Table.ReplaceValue(Source,each [Data],each Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),","),Replacer.ReplaceValue,{"Data"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0gkoykxO1YGAwNLEvJLMkkodx9z80rwSkFBIYgWQVIrVASq1BLIMDXR0jHQQwBIoFwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    Custom1 = Table.ReplaceValue(Source,each [Data],each Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),","),Replacer.ReplaceValue,{"Data"})
in
    Custom1

View solution in original post

2 REPLIES 2
laganlee
Helper II
Helper II

Thanks a lot Vijay! That is a great solution 😀

Vijay_A_Verma
Super User
Super User

If you want it in a separate column, use following formula in a custom column (name of the column to be converted is Data)

= Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),",")

If you want in column replacement, issue following statement where Source is the previous step name

Table.ReplaceValue(Source,each [Data],each Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),","),Replacer.ReplaceValue,{"Data"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0gkoykxO1YGAwNLEvJLMkkodx9z80rwSkFBIYgWQVIrVASq1BLIMDXR0jHQQwBIoFwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    Custom1 = Table.ReplaceValue(Source,each [Data],each Text.Combine(List.RemoveItems(Text.Split([Data],","),{""}),","),Replacer.ReplaceValue,{"Data"})
in
    Custom1

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors