Forum Discussion
aqeel_shaikh
2 years agoHelper III
Need help in power query
My sample data is
1234-567-AB$C#DEF-123
expectation is to remove bold special character in RED and provide this result "1234-567ABCDEF123"
Check this:
Result
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZdTJbtswEAbgdwly7FizcTtKdougtV0DElqgaZCnyPt3LFKKOT3q489tSOr19QkJsMSBEJiBnt6+dKSNNBITpJ/DPDOJNAuJIVSjXC0RxdX+fiBynJ+ZOOxNGajGP82GdVZstM2oThVCpAT0jpaqC0pIfJmhBIUbYyWi73RZgCLBtQmf9LJ8Xemm1VhOxVJrz410jGtHfKBv6FKi3GRZ4SS5lDIw1q3+mCTcrl1L/P38iZdMmXEQiNtnER3upT5iq14zBtQjYnCWRtuzN8slZ/fxtjlESYYME2I+Hnt7sdF+nZulQveltH7XcSYMaZHJVlLrfZNRVPEM9UAWwZBHiHb+GeHP1K4JkRIWOKSA8wxC0652pIfIAYzjuC2ENdus1uwheEgOwn+QHSSX4Ig9qMYeCooDQg/dLOxXaiC0VzmHtaTcg1XCgzpgn2DxUHrghwOv4Lsw+4SSB58IfpbkE8klyn5pd9grFmT9pSCnc0cZ7HJ2xF3IHuxgD9N+HuP10XJ+IUZpNiMfou357R8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), Ad_Transformed = Table.AddColumn(Source, "Transformed", each [ numbers = {"0".."9"}, alphabets = {"a".."z", "A".."Z"}, a = Text.ToList([Column1]), b = List.Select(a, each not List.Contains(alphabets & numbers, _)), //Characters to remove/replace c = Text.Combine(List.Transform(a, each if List.Contains(b, _) then "-" else _)), //replace other special characters with "-" d = Text.Combine(List.RemoveItems(Splitter.SplitTextByDelimiter("-")(c), {""}), "-"), //remove extra dashes e = Splitter.SplitTextByCharacterTransition(each true, (x)=> List.Contains(alphabets & numbers, x))(d), //split any|text f = Text.Combine(List.Transform(e, each if List.Contains(alphabets, _, (x,y)=> Text.StartsWith(y,x)) then Text.Start(_,1) else _)), g = Splitter.SplitTextByCharacterTransition((x)=> List.Contains(alphabets & numbers, x), each true)(f), //split text|any h = Text.Combine(List.Transform(g, each if List.Contains(alphabets, _, (x,y)=> Text.EndsWith(y,x)) then Text.End(_,1) else _)) ][h], type text) in Ad_Transformed
10 Replies
- AlienSxSuper User
Text.Combine( List.Transform( Splitter.SplitTextByEachDelimiter({"-"})("1234-567-AB$C#DEF-123"), (x) => Text.Combine(List.RemoveItems(Text.ToList(x), {"-", "#", "$"})) ), "-" )- aqeel_shaikhHelper III
AlienSx - Hi, I have multiple lines so how i would use the above to get the result...any alternate?
- AlienSxSuper User
Table.TransformColumns to change existing column or Table.AddColumn to create a new one is totally up to you
let lines = #table ({"lines"}, {{"1234-567-AB$C#DEF-123"}, {"1234-567-AB$C#DEF-123"}}), rm = Table.TransformColumns( lines, {"lines", (x) => Text.Combine( List.Transform( Splitter.SplitTextByEachDelimiter({"-"})(x), (y) => Text.Combine(List.RemoveItems(Text.ToList(y), {"-", "#", "$"})) ), "-" )} ) in rm