Forum Discussion
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!
- Anonymous2 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.
- Split the string to a list.
- Reverse the list.
- 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
- collinsgSolution Sage
Good day fred65,
I'm glad you found a solution for yourself. Here is an alternative.
- Split the string to a list.
- Reverse the list.
- 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.
- AnonymousNot applicable
I think I found another way around it using Extract text
= Table.TransformColumns(#"Added Custom", {{"Country", each Text.BeforeDelimiter(_, ","), type text}})