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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
wpf_
Post Prodigy
Post Prodigy

Some Phone numbers come in with hyphens and some do not

I am importing from dynamics365 data source.  In the data source, all phone numbers has the format xxx-xxx-xxxx, but when it's imported into BI, some become xxxxxxxxxx, and some (xxx) xxx-xxxx.  Most retained the format.  The data type in the data source is phone number, but i guess because BI does not have the format it automatically converted it to type text.  

 

What's the best way to convert those back to the xxx-xxx-xxxx format?  Thanks.

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @wpf_ 

 

According to your description, I think you can use custom format strings:###-###-#### in Power BI Desktop.

Like this: 

vjaneygmsft_0-1639722977468.png

vjaneygmsft_1-1639723092815.png

If there are numbers and - in the column, you can first unify them into numbers then format in PQ.

Like this:

vjaneygmsft_0-1639723837229.png

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

View solution in original post

11 REPLIES 11
v-janeyg-msft
Community Support
Community Support

Hi, @wpf_ 

 

According to your description, I think you can use custom format strings:###-###-#### in Power BI Desktop.

Like this: 

vjaneygmsft_0-1639722977468.png

vjaneygmsft_1-1639723092815.png

If there are numbers and - in the column, you can first unify them into numbers then format in PQ.

Like this:

vjaneygmsft_0-1639723837229.png

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

@v-janeyg-msft I folowed your steps but when i try to access it from a measure i get this msg:

 

wpf__1-1640122588310.png

 

@wpf_   The method I provide is only applicable to column because measure can't be seen in the model view and will change as the context changes, it can't be fixed. Have you tried?

 

Best Regards,
Community Support Team _ Janey

@v-janeyg-msft 

 

I got it working now by following your above post, converting the type of whole number then doing a custom formatting.  The error that i was having was because I still had some unclean data in there ex: ), and spaces.  Once i cleaned those up i just used custom formatting.  

 

But one thing I don't really get is why do I have to conver to whole number first?  Why can't I custom format with text type? 

@wpf_  Hello

 

Custom format strings follow the VBA style syntax. Types like date and numbers can be formatted.

Check this:

Use custom format strings in Power BI Desktop - Power BI | Microsoft Docs

I don't know much about VBA. But I think you can understand it this way: Text type is more complicated, it can contain numbers, decimal points and letters, so it is difficult to achieve uniformity.

 

Best Regards,
Community Support Team _ Janey

@v-janeyg-msft ,

 

I followed your steps and when accessing it from a measure I am gtting this message.  

wpf__0-1640122382276.png

 

smpa01
Super User
Super User

@wpf_  please try this

let
   
   regex=let   fx=(input)=>
    Web.Page(
        "<script>
            var x='"&input&"'; // this is the input string for regex
            var b=x.match(/\d{3}/gm).toString().replace(/,/gm,'-');  
            document.write(b);
        </script>"){0}[Data]{0}[Children]{1}[Children]{0}[Text] in fx,
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjE1M7ewVIrVAfN0gVxdGF8DKKAJF4gFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each regex([Column1]))
in
    #"Added Custom"

 

https://community.powerbi.com/t5/Community-Blog/Using-JavaScript-in-power-query-for-regex-Part2/ba-p...

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 

 

Not sure if i am ready for javascript in BI yet. 

Samarth_18
Community Champion
Community Champion

Hi @wpf_ ,

 

You can create a custom column like this:-

Column = FORMAT(Phone_number[Phoneno],"###-###-####")

output:-

Samarth_18_0-1639505035154.png

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

 

I can't use format function in calculated column because i am using directquery

Samarth_18
Community Champion
Community Champion

@wpf_ ,Okay then you can create a measure with above code.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.