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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Alma1992
Regular Visitor

Concatenates

Hi. I have got this excel formula that concatenates the country code & phone number and ensure the output doesn’t duplicate the country code if it’s already within the phone number (see below). I would like to do it in power BI. How can I do it, can you please advise? Thanks in advance!

=IF(LEFT(H2, LEN(MID(G2, 6, LEN(G2)-6))) = MID(G2, 6, LEN(G2)-6), "+" & MID(G2, 6, LEN(G2)-6) & MID(H2, LEN(MID(G2, 6, LEN(G2)-6))+1, LEN(H2)), "+" & MID(G2, 6, LEN(G2)-6) & H2

 

Alma1992_0-1716538606741.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Alma1992 ,

You can follow these steps below:

1.Add a new column.

vyifanwmsft_1-1716775586121.png

 

CodeNumber = 
VAR code =
    REPLACE ( [Country Code], 1, 4, "" )
VAR result =
    LEFT ( code, SEARCH ( ")", code ) - 1 )
RETURN
    result

Change the Data Type to Whole Number:

vyifanwmsft_0-1716775526684.png

 

2.Add a new column.

PhoneNumber = 
IF (
    'Table'[CodeNumber] < 10,
    LEFT ( 'Table'[Phone], 1 ),
    LEFT ( 'Table'[Phone], 2 )
)

 Change the Data Type to Whole Number:

vyifanwmsft_2-1716775670886.png

3.Add a new column.

FinalResult = 
IF (
    'Table'[CodeNumber] = 'Table'[PhoneNumber],
    "+" & 'Table'[Phone],
    "+" & 'Table'[CodeNumber] & 'Table'[Phone]
)

 

Final output:

vyifanwmsft_3-1716775745127.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Alma1992 ,

You can follow these steps below:

1.Add a new column.

vyifanwmsft_1-1716775586121.png

 

CodeNumber = 
VAR code =
    REPLACE ( [Country Code], 1, 4, "" )
VAR result =
    LEFT ( code, SEARCH ( ")", code ) - 1 )
RETURN
    result

Change the Data Type to Whole Number:

vyifanwmsft_0-1716775526684.png

 

2.Add a new column.

PhoneNumber = 
IF (
    'Table'[CodeNumber] < 10,
    LEFT ( 'Table'[Phone], 1 ),
    LEFT ( 'Table'[Phone], 2 )
)

 Change the Data Type to Whole Number:

vyifanwmsft_2-1716775670886.png

3.Add a new column.

FinalResult = 
IF (
    'Table'[CodeNumber] = 'Table'[PhoneNumber],
    "+" & 'Table'[Phone],
    "+" & 'Table'[CodeNumber] & 'Table'[Phone]
)

 

Final output:

vyifanwmsft_3-1716775745127.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.