Sub topic 7
Splitting and Merging Columns
This chapter assumes you can open the Power Query Editor, read the Applied Steps pane, and set data types. It also assumes you have trimmed and cleaned text, as covered in the previous chapter. Splitting and merging columns builds directly on that cleanup, because stray spaces and mixed delimiters are the most common reasons a split goes wrong.
Why split and merge columns
Source data often packs several facts into one cell. Examples are "Smith, Anna" in a name column, "2025-Q3-North" in a code column, or "12 Oak St, Leeds" in an address column. Analysis needs each fact in its own column. The opposite problem also appears. You may need a single key such as Region-Product to match rows in another query.
Power Query handles both cases with recorded steps. When new data arrives and you refresh, the same split or merge applies to every row.
Splitting a column by delimiter
A delimiter is a character, or a short string, that separates parts of a value. Common delimiters are the comma, the space, the hyphen, and the tab.
To split a column:
- Select the column in the preview.
- Choose Home > Split Column > By Delimiter.
- Pick a delimiter from the list, or choose Custom and type your own.
- Choose where to split: Left-most delimiter, Right-most delimiter, or Each occurrence of the delimiter.
- Open Advanced options to set the number of columns, the quote character, and whether to split into columns or into rows.
- Select OK.
Power Query names the new columns after the original, with a numeric suffix. If the column was FullName, you get FullName.1 and FullName.2. Rename them straight away so later steps are readable.
The three split positions
The position setting decides what happens when a value contains more than one delimiter.
| Setting | Value `North-East-2025` split on `-` | Result |
|---|---|---|
| Left-most delimiter | Split once at the first hyphen | `North` and `East-2025` |
| Right-most delimiter | Split once at the last hyphen | `North-East` and `2025` |
| Each occurrence | Split at every hyphen | `North`, `East`, and `2025` |
Choose the setting that matches the structure of your data. If a code always ends in a year, right-most is the safest option.
Reading the M behind a split
The editor writes a Table.SplitColumn call. It looks like this:
let
Source = Excel.CurrentWorkbook(){[Name="Codes"]}[Content],
Typed = Table.TransformColumnTypes(Source, {{"Code", type text}}),
Split = Table.SplitColumn(
Typed,
"Code",
Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv),
{"Year", "Quarter", "Region"}
),
Retyped = Table.TransformColumnTypes(Split, {{"Year", Int64.Type}, {"Quarter", type text}, {"Region", type text}})
in
RetypedThe fourth argument lists the new column names. This is the main point to check when you edit the step by hand. If a refresh brings in a value with more parts than the list allows, the extra parts are dropped silently when you list the names yourself. Keep that in mind when the source format can change.
Splitting by number of characters and by position
Some data has no delimiter. A product code such as NA2025A may use fixed positions: two letters for the region, four digits for the year, one letter for the grade.
Use Split Column > By Number of Characters. You can split once, as far left or right as possible, or repeatedly. For mixed lengths, use By Positions and enter the start positions, for example 0,2,6. Positions start at zero.
Related options appear in the same menu:
- By Lowercase to Uppercase splits
SalesRegionintoSalesandRegion. - By Uppercase to Lowercase splits at the point where capitals change to lowercase.
- By Digit to Non-Digit and By Non-Digit to Digit separate numbers from letters, such as
Q3intoQand3.
Splitting into rows
Sometimes a cell holds a list, such as Red; Blue; Green. If you split it into columns, you get three columns that are awkward to analyse. Splitting into rows gives one row per item, with the other columns repeated.
In the Split Column by Delimiter dialog, expand Advanced options and select Rows. Use this when the number of items varies from row to row. A column-based split would need as many columns as the longest list.
Common problems with splits
Extra spaces after the split
A value like Smith, Anna split on a comma gives Smith and Anna, with a leading space. Either split on the two-character delimiter , , or apply Format > Trim to the new columns. The second option is safer when spacing is inconsistent.
Missing delimiters
If a row has no delimiter, the whole value lands in the first new column and the later columns hold null. That is correct behaviour, but check for it. Filter the second column for null to find rows that did not follow the pattern.
Numbers turned into the wrong type
After a split, Power Query often adds a Changed Type step automatically. It guesses types from the first rows of data. A code such as 007 becomes the number 7, and the leading zeros are lost. Delete the automatic type step, or set the column to text yourself, when the digits are an identifier and not a quantity.
Column count changes between refreshes
The number of columns produced by an "each occurrence" split is fixed when you create the step, and the generated step names them explicitly. If a refreshed file contains a value with extra delimiters, the extra pieces are not given new columns. Test with the longest realistic value before you rely on the query.
Merging columns
Merging joins the values of two or more columns into one. Select the columns in the order you want them joined, then choose Transform > Merge Columns. Hold Ctrl and click each column header to control the order.
The dialog asks for:
- A separator: none, space, comma, semicolon, colon, equals sign, tab, or a custom string.
- A new column name. The default is
Merged.
The editor replaces the original columns with the merged one. If you want to keep the originals, use Add Column > Merge Columns instead. This builds the same result in a new column and leaves the sources in place. The second route is useful when you need both the parts and a combined key.
The M behind a merge
let
Source = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
Keyed = Table.AddColumn(
Source,
"Key",
each Text.Combine({[Region], [Product]}, "-"),
type text
)
in
KeyedText.Combine takes a list of text values and a separator. It skips null items in the list, so a missing Product gives North and not North-. That differs from the & operator, which returns null if either side is null. Use Text.Combine when blanks are possible.
Merging numbers and dates
Merge Columns requires text. If you select a number or date column, Power Query converts it to text with the current locale's format. A date may then appear as 27/11/2026 on one computer and 11/27/2026 on another. When the result is used as a key, convert the pieces explicitly in a custom column, for example with Date.ToText([Date], "yyyy-MM-dd"), so the output does not depend on the machine.
Splitting and merging together
A frequent pattern is to split a value, fix one part, then merge it back. Suppose phone numbers arrive as 0044-20-7946-0000 and you want +44 20 7946 0000.
- Split by each occurrence of
-. - Replace the leading
0044with+44. - Merge the four columns with a space as separator.
Each stage appears as its own step, so you can click an earlier step to inspect the data at that point.
Splitting and the Applied Steps list
Every split adds steps such as Split Column by Delimiter and Changed Type. Two habits help here:
- Rename steps with a description of intent, for example
Split Code into Year Quarter Region. - Place the split after text cleanup. Trimming and replacing first means the delimiter is consistent.
If you insert a step before an existing split and it changes the column names, later steps fail with an error such as The column 'Code' of the table wasn't found. Fix it by correcting the name in the failing step or by moving your step after the split.
Choosing between split methods
| Situation | Best choice |
|---|---|
| Values separated by a clear character | By Delimiter |
| Fixed-width codes | By Number of Characters or By Positions |
| CamelCase or letter-digit boundaries | By case change or digit change |
| A variable-length list in one cell | By Delimiter, split into rows |
| A pattern too complex for the menu | A custom column with `Text.BeforeDelimiter`, `Text.AfterDelimiter`, or `Text.Middle` |
Exercise
A column named Code holds values such as EU-North-2025, EU-South-East-2025, and US-2025. You need a Region column (everything between the first and last hyphen) and a Year column (the part after the last hyphen). Which split settings would you use, and what problem would a split on each occurrence cause?
Show answer
Split by delimiter - at the right-most delimiter. This gives Year in the second column and the rest, such as EU-South-East, in the first. A split on each occurrence would create a different number of parts per row (three, four, or two). Because the step names its columns explicitly, extra parts would be dropped or misaligned. You would then trim the leading EU- or US- part with a second split on the left-most delimiter if you want it separate. Note that US-2025 has no middle region, so its Region would be US, which you should check for after splitting.
Exercise
You merge a Region column and a Product column with a hyphen. Some rows have a blank Product, and you do not want a trailing hyphen. Which M function should you use in a custom column, and why does it work?
Show answer
Use Text.Combine({[Region], [Product]}, "-"). It skips null items in the list, so a null Product returns just the Region. If the blank cells contain empty strings and not nulls, the hyphen would still appear, so replace empty strings with null first.