Forum Discussion

Alma1992's avatar
Alma1992
Regular Visitor
2 years ago
Solved

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

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    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.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.