Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Swap text based on Delimiter

Hi All,
I was wondering if there was a simple way to swap text values in a column based on a comma delimiter as I would like the split the column to a 'City' column?

Example:

My column named 'Country' has text values of
Sydney, Australia

I want to change these values to:

Australia, Sydney

Any assistance greatly appreciated!


 

  • Anonymous's avatar
    Anonymous
    2 years ago

    I think I found another way around it using Extract text

    = Table.TransformColumns(#"Added Custom", {{"Country", each Text.BeforeDelimiter(_, ","), type text}})
  • Good day fred65,

    I'm glad you found a solution for yourself. Here is an alternative.

    1. Split the string to a list.
    2. Reverse the list.
    3. Combline the list to a string.

    The code is as follows. Replace "Source" with the name of your previous step.

    = Table.TransformColumns(
    Source,
    {
    {"Country", each Text.Combine(List.Reverse(Text.Split(_, ", ")), ", ")}
    }
    )

     Hope this helps.

2 Replies

  • collinsg's avatar
    collinsg
    Solution Sage

    Good day fred65,

    I'm glad you found a solution for yourself. Here is an alternative.

    1. Split the string to a list.
    2. Reverse the list.
    3. Combline the list to a string.

    The code is as follows. Replace "Source" with the name of your previous step.

    = Table.TransformColumns(
    Source,
    {
    {"Country", each Text.Combine(List.Reverse(Text.Split(_, ", ")), ", ")}
    }
    )

     Hope this helps.

  • Anonymous's avatar
    Anonymous
    Not applicable

    I think I found another way around it using Extract text

    = Table.TransformColumns(#"Added Custom", {{"Country", each Text.BeforeDelimiter(_, ","), type text}})