Forum

No wildcards in M? ...
 
Notifications
Clear all

No wildcards in M? How do I replace a text string between two known characters

2 Posts
2 Users
0 Reactions
79 Views
(@mlinke)
Posts: 39
Trusted Member
Topic starter
 

I am importing data from a spreadsheet that I don't control. It has addresses that mostly look like this:

123 Sesame [ST] Street

Although some don't have the [ST] bit.

I want to remove the [ST] bit so the address is 123 Sesame Street.

I thought it would be easiest to do this:

= Table.ReplaceValue(#"Changed Type","[wildcard for any characters] ","",Replacer.ReplaceText,{"Address"})

But it seems that M doesn't have wildcards. I used the Column from Examples to get this (my If statement added to eliminate errors from the few addresses that don't contain [x]:

= if Text.Contains ([Address], "[") then Text.Combine({Text.Proper(Splitter.SplitTextByDelimiter("[", QuoteStyle.None)([Address]){0}?), Text.Start(Splitter.SplitTextByDelimiter("] ", QuoteStyle.None)([Address]){1}?, Text.Length(Splitter.SplitTextByDelimiter("] ", QuoteStyle.None)([Address]){1}?) - 2)}) else [Address]

But I don't like it because I'm getting a "cannot convert null value to logical" error that I'm pretty sure relates to it.

 

Is there something simpler I can do to achieve this?

 

Thanks, Mardi

 
Posted : 15/02/2019 10:04 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Mardi,

This video explains how you can use a mapping table to bulk replace the parts of the address you want to remove: https://www.youtube.com/watch?v=MLrRlPh_ZFQ

Mynda

 
Posted : 16/02/2019 1:28 am
Share: