Table.CombineColumns 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.CombineColumns function in Power Query joins two or more columns into one new column, like putting first and last names together. The original columns are removed, and the new column takes their place in the table.

In this article, I’ll show you how to use it with practical examples, from a simple full name to skipping blank cells and building your own combine rule.

Follow along with the example file

Table.CombineColumns Function Examples.xlsx

Download

Table.CombineColumns Function Syntax

= Table.CombineColumns(table as table, sourceColumns as list, combiner as function, column as text) as table
  • table – the table that has the columns you want to combine. This is usually the previous step, such as Source.
  • sourceColumns – the names of the columns to combine, as a list in curly brackets, such as {"First Name","Last Name"}. The values are joined in the order you list them.
  • combiner – a function that tells Power Query how to join the values. Most of the time, this is Combiner.CombineTextByDelimiter, which puts a separator (like a space or a comma) between the values.
  • column – the name of the new column, in double quotes.

What it returns – a table where the listed columns are replaced by one new column. The new column sits where the leftmost of those columns was.

The Table.CombineColumns function works in Power Query in Excel for Microsoft 365, 2024, 2021, 2019, 2016, and Excel for Mac (Microsoft 365), as well as in Power BI.

When to Use the Table.CombineColumns Function

Use this function when you need to:

  • Put first and last names together into a full name
  • Join address parts like street, city, and state into one column
  • Build codes or IDs from a text column and a number column
  • Combine columns where some cells are blank, without getting extra commas
  • Create text for a CSV file where some values already contain commas
  • Build values like email addresses using your own rule
  • Combine every column except one, even when new columns get added later

Example 1: Combine First and Last Name

Let’s start with the most common use, putting first and last names together.

Below is an employee list with separate First Name and Last Name columns, and I want to combine them into a Full Name column.

Employees table with Emp ID, First Name, Last Name and Department 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.CombineColumns(Source,{"First Name","Last Name"},Combiner.CombineTextByDelimiter(" ",QuoteStyle.None),"Full Name")

Result: a table with Emp ID, Full Name, and Department, where Full Name shows values like Robert Campbell

First Name and Last Name replaced by one Full Name column, like Robert Campbell

Here, the formula takes the First Name and Last Name values in each row and joins them with a space, which is the " " inside the Combiner.CombineTextByDelimiter function.

QuoteStyle.None tells it not to add any quotes to the values (Example 6 shows when quotes come in).

The two original columns are gone, and the new Full Name column sits right where First Name used to be.

If you want to keep First Name and Last Name as they are, add the full name as a new column with the Table.AddColumn function instead.

The new column needs a name that isn’t already in the table. If you call it “Department” here, you get an error that says “The field ‘Department’ already exists in the record.”

Example 2: Create a “Last, First” Name

Sometimes you need names with the last name first, like on a sign-in sheet or a sorted list.

Below is a list of workshop attendees with their first name, last name, and session, and I want a Name column that shows the last name, a comma, and then the first name.

Workshop attendees with First Name, Last Name and Session columns

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

= Table.CombineColumns(Source,{"Last Name","First Name"},Combiner.CombineTextByDelimiter(", ",QuoteStyle.None),"Name")

Result: a table with Name and Session, where Name shows values like Evans, Lillian

Name column in Last, First format, like Evans, Lillian

Here, Last Name comes first in the list, so its value comes first in the result. The separator is a comma followed by a space, ", ", so you get “Evans, Lillian” and not “Evans,Lillian”.

Note that the list order only changes the order of the values. The new Name column still goes where the leftmost source column (First Name) was, which is the first column here.

Example 3: Combine Three Columns into One Address

You’re not limited to two columns. You can list as many as you need.

Below is a customer list with the street, city, and state in separate columns, and I want them all in one Address column.

Customer list with Street, City and State in separate columns

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

= Table.CombineColumns(Source,{"Street","City","State"},Combiner.CombineTextByDelimiter(", ",QuoteStyle.None),"Address")

Result: a table with Customer and Address, where Address shows values like 12 Oak St, Dayton, OH

Street, City and State combined into one Address column

Here, the same separator goes between every pair of values, so you get a comma and a space after the street and after the city. The three columns are replaced by the single Address column.

Example 4: Combine a Text Column with a Number Column

This one is easy to get wrong. Combiner.CombineTextByDelimiter only joins text, so a column with numbers needs one extra step.

Below is a product list with a text category code and a numeric item number, and I want to create an SKU like FUR-1042.

Product list with a text Category code and a numeric Item No

If you combine these two columns directly, every SKU cell shows Error. Click one, and you’ll see “We cannot apply operator & to types Number and Text.”

The fix is to change the Item No column to text first. Since that needs two steps, here’s the full query, which reads the data from an Excel table named Products.

Go to Data > Get Data > From Other Sources > Blank Query, open the Advanced Editor (Home > Advanced Editor), and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Products"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Item No",type text}}),
#"Merged Columns" = Table.CombineColumns(#"Changed Type",{"Category","Item No"},Combiner.CombineTextByDelimiter("-",QuoteStyle.None),"SKU")
in
#"Merged Columns"

Result: a table with SKU and Product, where SKU shows values like FUR-1042

SKU column that joins Category and Item No with a hyphen, like FUR-1042

Here, the Changed Type step turns 1042 into the text “1042”. After that, both columns hold text, and the Merged Columns step joins them with a hyphen.

The same thing applies to dates and any other non-text column. Convert it to text first, and then combine.

Follow along with the example file

Table.CombineColumns Function Examples.xlsx

Download

Example 5: Skip Blank Cells When Combining

When some cells are blank, Combiner.CombineTextByDelimiter still adds the separator for them. So a blank Line 2 gives you something like “41 Bay Rd, , Mesa”, with an extra comma.

Below is a list of shipping addresses where some orders have a Line 2 (like an apartment number) and some don’t, and I want one clean Address column.

Shipping orders where some Line 2 cells are blank

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

= Table.CombineColumns(Source,{"Line 1","Line 2","City"},each Text.Combine(_,", "),"Address")

Result: a table with Order ID and Address, where Address shows 8 Elm St, Apt 3, Akron for the first order and 41 Bay Rd, Mesa for the second

Address column with no extra commas for the blank Line 2 cells

Here, instead of Combiner.CombineTextByDelimiter, the combiner is each Text.Combine(_,", "). For every row, Table.CombineColumns hands this function a list of that row’s values, and the underscore _ stands for that list.

The Text.Combine function joins the list with a comma and a space, and it skips null values. Blank cells come into Power Query as null, so they’re simply left out, along with their extra comma.

Important: Text.Combine skips null, but not a cell that holds a space or empty text. If your data has such cells, replace those values with null before combining so they get skipped too.

Example 6: Quote Values That Contain the Separator (QuoteStyle.Csv)

Here’s what the QuoteStyle part of the formula is for. It matters when a value already contains the separator you’re using.

Below is a merchandise list where some Sizes values have commas in them (like S, M, L), and I want to combine Item and Sizes into comma-separated text that I can paste into a CSV file.

Merchandise list where some Sizes values contain commas

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

= Table.CombineColumns(Source,{"Item","Sizes"},Combiner.CombineTextByDelimiter(",",QuoteStyle.Csv),"CSV Text")

Result: a table with CSV Text and Price, where CSV Text shows Polo Shirt,”S, M, L” for the first row and Cap,One Size for the second

CSV Text column where only the sizes with commas are wrapped in double quotes

Here, QuoteStyle.Csv puts double quotes around any value that contains the comma. That way, a program reading the CSV knows “S, M, L” is one value and not three.

Values without a comma, like One Size, are left as they are.

With QuoteStyle.None, the first row would be Polo Shirt,S, M, L, and there’d be no way to tell where the item ends and the sizes begin.

If you leave out the QuoteStyle argument completely, you get the Csv behavior. That’s why it’s worth writing QuoteStyle.None when you don’t want quotes, like in the earlier examples.

Example 7: Build Email Addresses with Your Own Combine Rule

The combiner doesn’t have to be one of the built-in Combiner functions. You can write your own, and this is where Table.CombineColumns gets really flexible.

Below is a list of new hires with their first and last names, and I want an Email column in the format first initial plus last name, all lowercase, followed by @company.com.

New hires with First Name, Last Name and Team columns

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

= Table.CombineColumns(Source,{"First Name","Last Name"},each Text.Lower(Text.Start(_{0},1) & _{1}) & "@company.com","Email")

Result: a table with Email and Team, where Email shows values like bstewart@company.com

Email column built from the first initial and last name, like bstewart@company.com

Here, the underscore _ is the list of values for each row, in the same order as the sourceColumns list. So _{0} is the first name and _{1} is the last name (the count starts at 0).

Text.Start(_{0},1) takes the first letter of the first name, the & joins it to the last name, and the Text.Lower function makes the whole thing lowercase. Then “@company.com” is added at the end.

Just like in Example 1, the First Name and Last Name columns are replaced by the Email column. If you need to keep the names too, use the same rule in a custom column with the Table.AddColumn function.

Example 8: Create Short Codes with Combiner.CombineTextByLengths

Power Query has a few other combiner functions, and Combiner.CombineTextByLengths is a handy one. It takes a set number of characters from each value.

Below is a list of offices with the department and city, and I want a short Code column made from the first three letters of each.

Office list with Department, City and Head Count columns

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

= Table.CombineColumns(Source,{"Department","City"},Combiner.CombineTextByLengths({3,3}),"Code")

Result: a table with Code and Head Count, where Code shows values like FinDen

Code column with the first three letters of the department and city, like FinDen

Here, {3,3} gives one length for each column. The first 3 characters of Department (Fin) are followed by the first 3 characters of City (Den), so Finance in Denver becomes FinDen.

If a value is shorter than its length, Power Query pads it with spaces. A department called “HR” would give “HR ” (with a trailing space) before the city part.

So this works best when every value is at least as long as the length you give.

If some values are shorter, use your own combiner instead, each Text.Start(_{0},3) & Text.Start(_{1},3). The Text.Start function never adds spaces, so “HR” stays “HR”.

Example 9: Combine Every Column Except One

In the examples so far, I typed out the column names. But you can also let Power Query work out the list for you.

Below is a volunteer list with a Skill 1, Skill 2, and Skill 3 column (some of them blank), and I want all the skills in one Skills column, even if a Skill 4 column gets added later.

Volunteer list with Skill 1, Skill 2 and Skill 3 columns, some blank

The data is in an Excel table named Volunteers. Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Volunteers"]}[Content],
SkillColumns = List.RemoveItems(Table.ColumnNames(Source),{"Volunteer"}),
#"Merged Columns" = Table.CombineColumns(Source,SkillColumns,each Text.Combine(_,", "),"Skills")
in
#"Merged Columns"

Result: a table with Volunteer and Skills, where Skills shows values like First Aid, Driving

All skills combined into one Skills column, with blanks skipped

Here, the Table.ColumnNames function gives a list of all four column names. The List.RemoveItems function then removes “Volunteer” from that list, which leaves the three Skill columns.

That list goes into Table.CombineColumns as the sourceColumns argument. And since the combiner is Text.Combine, the blank skills are skipped, just like in Example 5.

When someone adds a Skill 4 column to the table, the query picks it up on the next refresh, with no change to the code.

The same goes for any other new column, though. A Phone column would get merged into Skills too, so add its name to the {"Volunteer"} list to leave it out.

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.