Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
samdep
Advocate II
Advocate II

Remove leading 1 (country code) in phone number in PQ when it appears

Hi All,

 

I was wondering if someone could help me with the code in Power Query (using the trim function?) to remove the leading 1 (or country code) from phone numbers... It's present in some records, but not all, so I'm in need of some sort or leftstrip type of conditional statement -- as the presence of the 1 is impacting my join/merge. 

 

Thanks in advance! 

3 ACCEPTED SOLUTIONS
watkinnc
Super User
Super User

Try this:

RemoveOne = Table.AddColumn(PreviousStepName, "Truncated", each if Text.StartsWith([PhoneNumberColumn], "1") then Text.RemoveRange([PhoneNumberColumn], 0) else [PhoneNumberColumn])

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

No need for the parentheses after the "if" in this case-you can remove them. But you DO need a final "else" clause:

each if Text.StartsWith([Client_Number__c],"1") then Text.RemoveRange([Client_Number__c],0) else if
[Client_Number__c] = "" then ""

else [Client_Number_c]

--Nate

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

your final conditional has to be else, not else if.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

6 REPLIES 6
watkinnc
Super User
Super User

Try this:

RemoveOne = Table.AddColumn(PreviousStepName, "Truncated", each if Text.StartsWith([PhoneNumberColumn], "1") then Text.RemoveRange([PhoneNumberColumn], 0) else [PhoneNumberColumn])

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

@watkinnc thanks so much, this worked perfectly! One follow-up, I am getting an error for fields where the phone number is blank in my new conditional column, so I assume a nested if/then should solve for that --

 

each if Text.StartsWith([Client_Number__c],"1") then Text.RemoveRange([Client_Number__c],0) else if(
[Client_Number__c] = "" then "")  

 

The second 'then' seems to be producing an error - but the error is 'Token RightParen expected', so I'm not sure what the issue is. Appreciate any feedback you/anyone may have. thx!

your final conditional has to be else, not else if.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

No need for the parentheses after the "if" in this case-you can remove them. But you DO need a final "else" clause:

each if Text.StartsWith([Client_Number__c],"1") then Text.RemoveRange([Client_Number__c],0) else if
[Client_Number__c] = "" then ""

else [Client_Number_c]

--Nate

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
V-pazhen-msft
Community Support
Community Support

@samdep 
Have you solved? If not, you might want to share a sample data and expected output.

 

Paul Zheng _ Community Support Team

AlB
Super User
Super User

Hi @samdep 

Do you want to show some examples to clarify when you want to remove the 1 and when not?

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors