In power bi using DAX how to add dashes to a phone number text

Viewed 211

I basically have a dataset that looks like this

Phone Number
          
  3444444444
  5555555555
  1234567890
           
  2244668899

Note that there are blanks so I can't just convert to a number using Value(), but for the existing data I would like to have it look like this

Phone Number
          
  344-444-4444
  555-555-5555
  123-456-7890
           
  224-466-8899

I started off with an if statement which says that if there are 10 numbers and the script would go from there

IF(LEN('dataset'[Phone Number])=10,{"Add Script here"},'dataset'[Phone Number])
1 Answers

You can use this aproach:

PhoneDashed = if ( ISBLANK(phone[phone]) || phone[phone] = "", BLANK(), FORMAT(CONVERT(phone[phone], INTEGER),"###""-""###""-""####" ))

enter image description here

Related