Forum Discussion
k_mathana
Helper II
5 years agoAdd Asterisk between Numeric and Alphabets
Hi,
Could you please kindly support to solve this requirement, I need to add Asterisk character between the Numeric and Alphabets .
| VALUE | Expected Result |
| 2Z-0001 | 2*Z*0001 |
| 124S120 | 124*S*120 |
| 524A135A | 524*A*135*A |
| 12 | 12 |
Hi k_mathana
Download sample PBIX file with solution
This Power Query M code does the job.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMorSNTAwMFSK1YlWMjQyCTY0MgCzTY1MHA2NTR2hEkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]), #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(List.Transform(Text.ToList([Value]), each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", _) then "*" & _ & "*" else _ ))), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if List.Last(Text.ToList([Custom])) = "*" then Text.Combine(List.RemoveLastN(Text.ToList([Custom]))) else [Custom]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"}) in #"Removed Columns"Regards
Phil
2 Replies
- PhilipTreacy
Super User
Hi k_mathana
Download sample PBIX file with solution
This Power Query M code does the job.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMorSNTAwMFSK1YlWMjQyCTY0MgCzTY1MHA2NTR2hEkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]), #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(List.Transform(Text.ToList([Value]), each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", _) then "*" & _ & "*" else _ ))), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if List.Last(Text.ToList([Custom])) = "*" then Text.Combine(List.RemoveLastN(Text.ToList([Custom]))) else [Custom]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"}) in #"Removed Columns"Regards
Phil
- k_mathana
Helper II
Thank you so much, it worked....