cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vuraltuysuz
Regular Visitor

How to replace a delimiter with an increase number ?

I have a column like  as below with a delimiter ";"

 

41.0223979,29.019951;41.0029523,29.0507535;41.0542336,28.9300755;40.999712,28.9225336

 

which i would like to convert like as below

 

41.0223979,29.019951wp0141.0029523,29.0507535wp0241.0542336,28.9300755wp0340.999712,28.9225336

 

Simply replacing each ";" into "wp??

?? means increasing number for each value

 

Can you please support how to do that?

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("HcnBDcAgDAPAXXijKHFwqdVREPuvQcr3bq02whxITXXIPCTG96NDRF6kTyavciDz6XhN6cWlbpJm4CLA+rb3AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Orig = _t]),
    #"Repl Delim" = Table.AddColumn(Source, "Repl Delim", each List.Accumulate({1..List.Count(Text.PositionOf([Orig], ";", 2))}, [Orig], (s,c) => Text.ReplaceRange(s, Text.PositionOf(s, ";"), 1, "pw" & Text.PadStart(Text.From(c), 2, "0"))))
in
    #"Repl Delim"

Screenshot 2021-10-15 011010.png

View solution in original post

2 REPLIES 2
mahoneypat
Super User
Super User

Here is another way to do it, but the one by @CNENFRNL is more elegant.  Add a custom column and put this formula in the pop-up box, replacing [StringColumn] with the name of your actual column.

 

let thislist = Text.Split([StringColumn], ";"),
wplist = List.Transform({1..List.Count(thislist)-1}, each "wp"& Text.PadStart(Number.ToText(_), 2, "0"))&{""},
zipped = List.Zip({thislist, wplist}),
concatenated = List.Transform(zipped, each Text.Combine(_, ""))
in
Text.Combine(concatenated, "")

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("HcnBDcAgDAPAXXijKHFwqdVREPuvQcr3bq02whxITXXIPCTG96NDRF6kTyavciDz6XhN6cWlbpJm4CLA+rb3AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Orig = _t]),
    #"Repl Delim" = Table.AddColumn(Source, "Repl Delim", each List.Accumulate({1..List.Count(Text.PositionOf([Orig], ";", 2))}, [Orig], (s,c) => Text.ReplaceRange(s, Text.PositionOf(s, ";"), 1, "pw" & Text.PadStart(Text.From(c), 2, "0"))))
in
    #"Repl Delim"

Screenshot 2021-10-15 011010.png

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.