Forum Discussion
AlB
7 years agoCommunity Champion
M: Split column with multiple spaces between fields
Hi all, Imagine we have a column in which we have different fields separated by an arbitrary number of spaces. Example: Column "1 Red 23 Yellow" and we want to...
- 7 years ago
One way to do this is to split the text into a list based on the delimiter, remove nulls, and then recombine the list into a string with just a single space between words.
= Table.TransformColumns(Source, {{"Column1", each Text.Combine(List.Select(Text.SplitAny(_, " "), each _ <> "")," "), type text}})or in expanded format
= Table.TransformColumns(
Source,
{{"Column1",
each Text.Combine(
List.Select(
Text.SplitAny(_, " "),
each _ <> ""
)
," "
),
type text
}}
)Then you can split this transformed column by the space delimiter.
AlexisOlson
7 years agoSuper User
- I modified steps I created with the GUI and added functions that I found in the function reference that looked useful. (Power Query M Function Reference) I don't think you could reproduce this particular code via the GUI, but there are other ways of tackling the problem with just the menu buttons that could potentially work. (E.g. Split By Delimiter > Transpose Table > Filter out blank rows > Transpose back)
- There are some awkward ways to transform individual cells, but I'd recommend only doing that as a last resort if you can't find a better method to process your data.
AlB
7 years agoCommunity Champion
Thanks very much AlexisOlson