Table.SplitColumn Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Table.SplitColumn function in Power Query splits one column of a table into several columns. You tell it which column to split and how to split it, such as at every space, at a hyphen, or after a fixed number of characters.

It’s the function you need when one column holds two or more pieces of information, like a full name or a product code.

Below, I’ll go through ten examples, from a basic name split to a split that creates as many columns as the data needs.

Follow along with the example file

Table.SplitColumn Function Examples.xlsx

Download

Table.SplitColumn Function Syntax

= Table.SplitColumn(table as table, sourceColumn as text, splitter as function, optional columnNamesOrNumber as any, optional default as any, optional extraColumns as any) as table
  • table – the table that has the column you want to split. This is usually the previous step, such as Source.
  • sourceColumn – the name of the column to split, in double quotes, such as "Full Name".
  • splitter – a splitter function that says how to cut the text, such as Splitter.SplitTextByDelimiter(" ") to split at every space or Splitter.SplitTextByLengths({2,3}) to split after a set number of characters.
  • columnNamesOrNumber (optional) – either a list of names for the new columns, such as {"First Name","Last Name"}, or the number of columns you want.
  • default (optional) – the value to put in a new column when a row doesn’t have enough parts to fill it. If you leave it out, those cells get null.
  • extraColumns (optional) – what to do when a row has more parts than there are new columns. The default, ExtraValues.Ignore, drops the extra parts. ExtraValues.Error gives those rows an error, and ExtraValues.List puts all the remaining parts in the last column as a list.

What it returns – the same table with the source column removed and the new columns in its place.

The new columns come out as text columns, even when the parts look like numbers. If you need numbers or dates, add a step that changes the data type after the split (Example 3 shows this).

I’ve tested the Table.SplitColumn function in Power Query in Excel for Microsoft 365. It’s also part of the Power Query M language that Power BI uses.

When to Use the Table.SplitColumn Function

Use this function when you need to:

  • Split full names into first and last names
  • Break a code like a SKU, an ID, or a location code into its parts
  • Split values like dimensions or a date stamp, and then turn the parts into numbers
  • Split text at only the first or the last delimiter
  • Separate a text prefix from the number that follows it
  • Split a comma-separated list into one column per item

Example 1: Split Full Names into First and Last Names

Let’s start with the most common use of this function, splitting names.

Below is an Excel table named Members with the full name of each gym member, and I want to split the Full Name column into First Name and Last Name columns.

Members table with Member ID, Full Name and Plan columns

To follow along, select any cell in the table and go to Data > From Table/Range to open it in the Power Query Editor. If Power Query adds a Changed Type step, use #"Changed Type" in place of Source in the formulas below.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.SplitColumn(Source,"Full Name",Splitter.SplitTextByDelimiter(" "),{"First Name","Last Name"})

Result: the Full Name column is replaced by First Name and Last Name columns, so Troy Brooks becomes Troy and Brooks

Full Name split into First Name and Last Name columns

Here, Splitter.SplitTextByDelimiter(" ") cuts each name at the space. The list {"First Name","Last Name"} gives the two new columns their names.

The new columns sit where Full Name was, between Member ID and Plan. The original Full Name column is gone, so if you still need it, duplicate it before you split.

Example 2: What Happens When You Skip the Column Names

The column names argument is optional, but leaving it out can quietly lose data. Let me show you why.

Below is an Excel table named Tickets with support tickets, where the Issue column has a category and a subcategory separated by a slash. I want to split Issue into two columns, and the first ticket only has a category.

Tickets table where the first ticket has only a category in the Issue column

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula, which doesn’t give any column names:

= Table.SplitColumn(Source,"Issue",Splitter.SplitTextByDelimiter("/"))

Result: only one new column, Issue.1, with the categories, and every subcategory is gone

Split without column names returns only Issue.1, and the subcategories are lost

When you don’t give column names, Power Query names the new columns Issue.1, Issue.2, and so on. It decides how many to create by looking at the first row only.

The first ticket says just Billing, which is one part, so Power Query creates one column. The subcategories in the other rows are dropped without any error, which makes this easy to miss.

To fix it, tell the function exactly which columns you want. Replace the formula in that step with this one:

= Table.SplitColumn(Source,"Issue",Splitter.SplitTextByDelimiter("/"),{"Category","Subcategory"})

Result: Category and Subcategory columns, with null in Subcategory for the two tickets that only have a category

Issue split into Category and Subcategory columns with null where there is no subcategory

Now every row gets both columns. T-1001 and T-1007 have no subcategory, so they get null there, which is what you’d expect.

You can also pass a number instead of a list, such as 2. That creates the right number of columns but names them Issue.1 and Issue.2, so a list of names saves you a Table.RenameColumns step later.

Important: Always give column names (or a number) when the rows don’t all have the same number of parts. Otherwise the first row decides the column count, and any parts beyond it are dropped silently.

Example 3: Split Dimensions and Convert Them to Numbers

Here’s a case where the parts are numbers, and you need them as real numbers after the split.

Below is an Excel table named Packages with each package’s size as length x width x height in one column, and I want Length, Width, and Height as three number columns.

Packages table with dimensions written as length x width x height

Load this table into Power Query the same way as in Example 1. Add a new step and use this formula:

= Table.SplitColumn(Source,"Dimensions (cm)",Splitter.SplitTextByDelimiter("x"),{"Length","Width","Height"})

This splits the size at each lowercase x, but the three new columns are text. Power Query names this new step Custom1, so right-click it in Applied Steps, choose Rename, and name it Split Dimensions.

Then add another step and use this formula to change the three columns to whole numbers:

= Table.TransformColumnTypes(#"Split Dimensions",{{"Length",Int64.Type},{"Width",Int64.Type},{"Height",Int64.Type}})

Result: Length, Width, and Height columns with whole numbers, such as 40, 30, and 20 for PKG-201

Length, Width and Height columns converted to whole numbers

Here, the first step does the split, and the second step turns the text “40” into the number 40. Now you can use these columns in calculations, like multiplying them to get the volume.

Note that the delimiter is case-sensitive. The sizes here use a lowercase x, so a size typed as 40X30X20 wouldn’t split.

Example 4: Fill Missing Parts with a Default Value

This next one comes up a lot with data where some rows are missing a part.

Below is an Excel table named Staff with each employee’s assignment written as department – team, and I want separate Department and Team columns. Some employees only have a department, and for them I want the Team column to say Unassigned instead of being blank.

Staff table where some assignments have only a department

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula:

= Table.SplitColumn(Source,"Assignment",Splitter.SplitTextByDelimiter(" - "),{"Department","Team"},"Unassigned")

Result: Department and Team columns, where Kimberly Perry, Savannah Cox, and Mitchell Marshall get Unassigned as their team

Assignment split into Department and Team, with Unassigned for missing teams

Here, the fifth argument, "Unassigned", is the default value. Whenever a row doesn’t have enough parts to fill all the new columns, Power Query uses it instead of null.

Also notice the delimiter is " - ", with a space on each side of the hyphen. If you split at just "-", every department would keep a trailing space and every team a leading space.

Example 5: Split at the First Delimiter Only

Sometimes the delimiter also shows up inside the values themselves, so you only want to split at the first one.

Below is an Excel table named AppLog with log entries, where each entry has a level like INFO or ERROR, then a colon and the message. I want the level and the full message in two columns, and some messages have a colon of their own.

App log entries with a level, a colon and a message

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula:

= Table.SplitColumn(Source,"Entry",Splitter.SplitTextByEachDelimiter({": "}),{"Level","Message"})

Result: Level and Message columns, where L-02 shows WARNING and the full message Disk space low: 12% left

Entries split at the first colon into Level and Message

Splitter.SplitTextByEachDelimiter takes a list of delimiters and uses each one once, in order. Here, the list has just one delimiter, ": ", so the text is split only at the first colon and space.

Everything after it stays together, including any colon inside the message.

If an entry had no colon at all, the whole entry would land in Level and Message would be null.

A plain Splitter.SplitTextByDelimiter(": ") would split at every colon. Then lines like WARNING: Disk space low: 12% left would lose the 12% left part, because there are only two columns.

Follow along with the example file

Table.SplitColumn Function Examples.xlsx

Download

Example 6: Split at the Last Delimiter

Now let’s do the opposite and split at the last delimiter. I’ll also show what goes wrong if you split at every delimiter instead.

Below is an Excel table named Stores with each store’s location as city-state, and I want separate City and State columns. Two of the cities, Winston-Salem and Wilkes-Barre, have a hyphen in their names.

Stores table with city-state locations, including hyphenated city names

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula, which splits at every hyphen:

= Table.SplitColumn(Source,"Location",Splitter.SplitTextByDelimiter("-"),{"City","State"})

Result: most rows look right, but S103 shows Winston and Salem, and S106 shows Wilkes and Barre

Splitting at every hyphen breaks Winston-Salem and Wilkes-Barre

Winston-Salem-NC has three parts, but there are only two columns. By default, the function drops the extra part (NC here) without any warning, so the result is wrong and you’d never know from the column headers.

The state is always the last part, so the fix is to split at the last hyphen only. Replace the formula in that step with this one:

= Table.SplitColumn(Source,"Location",Splitter.SplitTextByEachDelimiter({"-"},QuoteStyle.Csv,true),{"City","State"})

Result: City has Winston-Salem and Wilkes-Barre in full, and State has NC and PA

Splitting at the last hyphen keeps the full city name and the state

This is the same Splitter.SplitTextByEachDelimiter from Example 5, with two more arguments. The third one, true, makes it start from the end of the text, so the split happens at the last hyphen.

The second argument, QuoteStyle.Csv, is the quote setting (Example 9 covers it). It doesn’t change anything here, and it’s only there because true has to go in the third spot, so the second spot needs a value.

If you’d rather have Power Query point out rows like these, add ExtraValues.Error to the plain split. It’s the sixth argument, so the fifth spot (the default value) needs a placeholder like null:

= Table.SplitColumn(Source,"Location",Splitter.SplitTextByDelimiter("-"),{"City","State"},null,ExtraValues.Error)

Now the rows with too many parts show an error in the preview, with the message “There were more columns in the result than expected.” The query also won’t load to a sheet until you fix those rows, so it’s a check, not a fix.

Example 7: Split Fixed-Width Codes by Length

When every value has the same structure with no delimiter, you can split by the number of characters.

Below is an Excel table named Inventory with a five-character location code for each item: one letter for the aisle, two digits for the shelf, and two digits for the bin. I want Aisle, Shelf, and Bin columns.

Inventory table with five-character location codes

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula:

= Table.SplitColumn(Source,"Location Code",Splitter.SplitTextByLengths({1,2,2}),{"Aisle","Shelf","Bin"})

Result: Aisle, Shelf, and Bin columns, so A0312 becomes A, 03, and 12

Location codes split into Aisle, Shelf and Bin by length

Here, Splitter.SplitTextByLengths({1,2,2}) takes 1 character, then the next 2, then the next 2. Since the new columns are text, the leading zero in 03 stays, which is what you want for a code.

Example 8: Separate Letters from Numbers

Here’s a split where neither a delimiter nor a fixed length works.

Below is an Excel table named Documents with document references like INV1042 and CN87, where the letters are the document type and the digits are the document number. I want them in two separate columns.

Documents table with references like INV1042 and CN87

The prefix can be two or three letters long, and the number can be two to four digits, so splitting by length won’t work. But in every reference, the letters end exactly where the digits start.

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula:

= Table.SplitColumn(Source,"Reference",Splitter.SplitTextByCharacterTransition({"A".."Z"},{"0".."9"}),{"Doc Type","Doc Number"})

Result: Doc Type and Doc Number columns, so INV1042 becomes INV and 1042, and CN87 becomes CN and 87

References split into Doc Type and Doc Number where letters change to digits

Splitter.SplitTextByCharacterTransition splits wherever a character from the first list is followed by a character from the second list. Here, {"A".."Z"} is every capital letter and {"0".."9"} is every digit, so the split happens where the letters end and the number starts.

Example 9: Split Text with Commas Inside Quotes

This one comes up when CSV data lands in a single column.

Below is an Excel table named Imported where each record is a line of comma-separated text with a company, an account type, and a region. I want them in three columns, and some company names, like “Hart, Moss & Co”, have a comma inside double quotes.

CSV records where some company names are in quotes because they contain a comma

Load this table into Power Query the same way as in Example 1. Then add a new step and use this formula:

= Table.SplitColumn(Source,"Record",Splitter.SplitTextByDelimiter(",",QuoteStyle.Csv),{"Company","Account Type","Region"})

Result: Company, Account Type, and Region columns, where the first row shows Hart, Moss & Co as the company, without the quotes

Records split into Company, Account Type and Region with quoted commas kept together

QuoteStyle.Csv tells the splitter to treat anything inside double quotes as one value, so the comma in “Hart, Moss & Co” doesn’t split it. It also removes the quotes from the result.

Splitter.SplitTextByDelimiter already does this by default, so you’d get the same result with just ",". Writing QuoteStyle.Csv anyway makes it obvious to anyone reading the query that the quotes are being handled.

The one to avoid here is QuoteStyle.None, which splits at every comma, even inside the quotes. The company name would be cut into two columns with the quote marks still on, and the region would be dropped.

Example 10: Create as Many Columns as the Data Needs

In all the examples so far, I typed the column names myself. That works when you know the number of parts, but not when it changes from row to row.

Below is an Excel table named Orders with the items in each order as a comma-separated list, and I want one column per item. The longest order has four items, but a new order next week might have five.

Cafe orders with one to four comma-separated items

Load this table into Power Query the same way as in Example 1. First, add a new step that finds the largest number of items in any order:

= List.Max(List.Transform(Source[Items],each List.Count(Text.Split(_,", "))))

This returns 4, since ORD-504 has four items. Right-click this step in Applied Steps, choose Rename, and name it MaxItems so the next formula can use it.

Now add another step and use this formula:

= Table.SplitColumn(Source,"Items",Splitter.SplitTextByDelimiter(", "),List.Transform({1..MaxItems},each "Item "&Text.From(_)))

Result: four columns, Item 1 to Item 4, with null wherever an order has fewer items

Items split into Item 1 to Item 4, with null where an order has fewer items

In the first step, Source[Items] gives the Items column as a list, and List.Transform runs the count once for each order (the _ is the current order’s text). Text.Split turns that text into a list of items, List.Count counts them, and List.Max returns the largest count.

In the second step, {1..MaxItems} is the list of numbers 1 to 4. List.Transform turns each number into a name, so you get Item 1, Item 2, Item 3, and Item 4.

Since the column names are worked out every time the query refreshes, a five-item order adds an Item 5 column on its own. It also avoids the first-row problem from Example 2, since the first order here has just one item.

If you don’t need custom names, you can pass MaxItems as the number of columns instead. That’s shorter, and the columns are named Items.1, Items.2, and so on.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.