Forum Discussion

Sambidha's avatar
Sambidha
New Member
5 years ago
Solved

Changing multiple row names

I have a table as below: 

CountryCostPercentage
Africa pacific region1k95%
Asia Region2k96%
Europe Region3k97%
Latin America Region4k98%

 

Here i want to change the country column fileds as like below : 

CountryCostPercentage
AFR1k95%
ASR2k96%
EUR3k97%
LAR4k98%

 

Can someone please with this.

Thanks in advance.

  • Hi Sambidha ,

     

    You can try to create a calculated column like so:

    Column =
    VAR LastWord =
        TRIM (
            RIGHT (
                SUBSTITUTE ( [Country], " ", REPT ( " ", LEN ( [Country] ) ) ),
                LEN ( [Country] )
            )
        )
    RETURN
        UPPER ( LEFT ( [Country], 2 ) & LEFT ( LastWord, 1 ) )
    

     

     

    Best regards

    Icey

     

    If this post helps,then consider Accepting it as the solution to help other members find it faster.

5 Replies

  • Daviejoe's avatar
    Daviejoe
    Memorable Member

    There are a couple ways of doing this.

     

    If you go into Power Query, in the Transform tab, replace values and replace the longer names entirely with the abbreviations.

     

    Or you create a table that has the current names with a new column added to house the abbreviations and then you have this as a linked Dimension table.

     

     

    • Sambidha's avatar
      Sambidha
      New Member

      Hi,

      Can you please help me with the query.

      Thanks.

      • Daviejoe's avatar
        Daviejoe
        Memorable Member

        Of course, give me five mins and I'll have a step through ready for you

  • Daviejoe's avatar
    Daviejoe
    Memorable Member

    Let me know if this helps (also, be mindful that Replace Values is case sensitive)

     

  • Icey's avatar
    Icey
    Community Support

    Hi Sambidha ,

     

    You can try to create a calculated column like so:

    Column =
    VAR LastWord =
        TRIM (
            RIGHT (
                SUBSTITUTE ( [Country], " ", REPT ( " ", LEN ( [Country] ) ) ),
                LEN ( [Country] )
            )
        )
    RETURN
        UPPER ( LEFT ( [Country], 2 ) & LEFT ( LastWord, 1 ) )
    

     

     

    Best regards

    Icey

     

    If this post helps,then consider Accepting it as the solution to help other members find it faster.