Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
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
Solved! Go to Solution.
Hi @Alma1992 ,
You can follow these steps below:
1.Add a new column.
CodeNumber =
VAR code =
REPLACE ( [Country Code], 1, 4, "" )
VAR result =
LEFT ( code, SEARCH ( ")", code ) - 1 )
RETURN
result
Change the Data Type to Whole Number:
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:
3.Add a new column.
FinalResult =
IF (
'Table'[CodeNumber] = 'Table'[PhoneNumber],
"+" & 'Table'[Phone],
"+" & 'Table'[CodeNumber] & 'Table'[Phone]
)
Final output:
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.
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.
Hi @Alma1992 ,
You can follow these steps below:
1.Add a new column.
CodeNumber =
VAR code =
REPLACE ( [Country Code], 1, 4, "" )
VAR result =
LEFT ( code, SEARCH ( ")", code ) - 1 )
RETURN
result
Change the Data Type to Whole Number:
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:
3.Add a new column.
FinalResult =
IF (
'Table'[CodeNumber] = 'Table'[PhoneNumber],
"+" & 'Table'[Phone],
"+" & 'Table'[CodeNumber] & 'Table'[Phone]
)
Final output:
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.
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 64 | |
| 53 | |
| 42 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 123 | |
| 104 | |
| 44 | |
| 32 | |
| 24 |