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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GraysonBishop23
Regular Visitor

Format Text Column as Phone Number in same column only using Power Query

Hello,

 

I've got a text column with phone numbers in the format "##########" and I want to convert it to the format "(###) ###-####". I've seen another thread that talks about splitting the column and recombining into another column, but I want to avoid that many transformations. I can't use DAX (I'm consuming this dataset elsewhere).

 

I might be trying to be too clever about it, but I feel like this is possible using a combination of Table.TransformColumns, Text.Format, and Text.ToList like this:

 

 

= Table.TransformColumns(#"Previous Step", {{"Unformatted Phone Number Column", each Text.Format("(#{1}#{2}#{3}) #{4}#{5}#{6}-#{7}#{8}#{9}#{10}",Text.ToList(_), type text}}))

 

 

I feel like this is close, but I can't quite work out the syntax. Any tips?

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

hello, @GraysonBishop23 

= Table.TransformColumns(
    #"Previous Step", 
    {"Unformatted Phone Number Column", 
     (x) => Number.ToText(Number.From(x), "(000) 000-0000")}
)

View solution in original post

3 REPLIES 3
GraysonBishop23
Regular Visitor

Thank you both! Both good options, but I went with @AlienSx since it seems a little cleaner

AlienSx
Super User
Super User

hello, @GraysonBishop23 

= Table.TransformColumns(
    #"Previous Step", 
    {"Unformatted Phone Number Column", 
     (x) => Number.ToText(Number.From(x), "(000) 000-0000")}
)
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @GraysonBishop23 

You could try the following transformation:

= Table.TransformColumns( #"Previous Step" , {{ "Custom", each "(" & Text.Range( _ , 0, 3 ) & ") " & Text.Range( _ , 3, 3 ) & "-" & Text.Range( _ , 6, 4 ) , type text}})

This is a good resource for learning about all the Text functions in Power BI.


Text Functions in Power Query M (150+ Examples) - BI Gorilla

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.