Phone Number Clean Up

cmcreynolds

Active Member
Joined
May 21, 2015
Messages
295
Hello

I'm bringing in data from Salesforce using Power Query and I have to work with a phone number field that has the phone numbers in a various assortment of formats.

examples:

618-345-9876
(618) 899-0000
6181234567
+16185678901


Is there a way to clean up the field to get them all in the same format? I was thinking something along the lines of getting rid of any non-numeric characters, and then excluding any left-leading 1s. (Ultimately, I'm only needing the US Area code anyway, no other part of the number). But I don't know how to do that in PQ.

Any suggestions?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello

Perhaps a little crude but I did a quick and dirty replacement of "+1", "(", ")" and space character, leaving only numbers, as Text. Exhibit below assumes that the numbers are in a table called Table2 and that the phone numbers are in a column called 'Phone Number'.

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MakeText = Table.TransformColumnTypes(Source,{{"Phone Number", type text}}),
    CleanTel = Table.AddColumn(MakeText, "Clean", each Text.Replace(Text.Replace(Text.Replace(Text.Replace(if Text.Start([Phone Number],2)="+1" then Text.Range([Phone Number],2) else [Phone Number],"(",""),")",""),"-","")," ",""))
in
    CleanTel
 
Upvote 0
Hello,
here is another solution

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Chtyp = Table.TransformColumnTypes(Source,{{"Phone Number", type text}}),
    UResult = Table.AddColumn(Chtyp, "Custom", each Text.Combine(List.RemoveMatchingItems(Text.ToList([Phone Number]),{"(",")","-","+"," "})))
in
    UResult
 
Upvote 0

Forum statistics

Threads
1,224,163
Messages
6,176,789
Members
452,743
Latest member
Unique65

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top