List.Combine 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 List.Combine function in Power Query joins two or more lists into one list. The items stay in the same order, with all the items of the first list, then the second, and so on.

In this article, I’ll show you how it works with practical examples, from joining two simple lists to building a list of column names on the fly.

Follow along with the example file

List.Combine Function Examples.xlsx

Download

List.Combine Function Syntax

List.Combine(lists as list) as list
  • lists – a list that holds the lists you want to join, such as {{1,2},{3,4}}. Each inner list can be typed in curly brackets or come from a table column. For example, if a query step called Source holds a table, Source[Order ID] gives its Order ID column as a list.

What it returns: A single new list with every item from the inner lists, in the order you gave them. Duplicates are kept, and the original lists aren’t changed.

The List.Combine function is part of the Power Query M language, so it works wherever Power Query does in Excel: Excel 365, 2024, 2021, 2019, and 2016 for Windows, and Excel for Microsoft 365 on Mac.

When to Use the List.Combine Function

Use this function when you need to:

  • Join two or more lists into one
  • Stack the values of a column from two different tables into one list
  • Get a unique list of values from several columns
  • Run a calculation, like a maximum, across several columns at once
  • Turn a list of lists (for example, text split in every row) into one flat list
  • Build a list of column names to keep, select, or remove

If you want to stack whole tables (all their rows and columns), use the Table.Combine function instead. And if you want to join text values into one text string, use Text.Combine.

Example 1: Combine Two Lists

Let’s start with the basics. Suppose you have the units sold in the first three days of a sale and in the next two days, and you want them in one list.

In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor that opens, type this formula in the formula bar:

= List.Combine({{120,85,240},{60,175}})

Result: 120, 85, 240, 60, 175

List.Combine joins the two lists into one: 120, 85, 240, 60, 175

Here, the outer curly brackets hold the two lists you want to join. List.Combine takes all the items from the first list and then adds the items from the second list.

This query types its lists right into the formula, so it doesn’t need a table on a worksheet. In the example file, go to Data > Queries & Connections and double-click a query in the pane to open it in the Power Query Editor.

Note the double curly brackets. List.Combine always takes one argument, which is a list of lists, so List.Combine({120,85,240},{60,175}) gives the error “2 arguments were passed to a function which expects 1.”

For two lists, the & operator does the same job, so {120,85,240} & {60,175} returns the same five numbers.

List.Combine becomes more useful when you have more lists, or when you don’t know in advance how many lists there will be (Example 6 shows this).

Example 2: Combine Three or More Lists

You’re not limited to two lists. Suppose you have three lists of products from three suppliers, and you want one list of all the products.

Create a new blank query and use this formula:

= List.Combine({{"Laptop","Monitor"},{"Keyboard"},{"Mouse","Webcam","Headset"}})

Result: Laptop, Monitor, Keyboard, Mouse, Webcam, Headset

Three product lists joined in order: Laptop, Monitor, Keyboard, Mouse, Webcam, Headset

Here, List.Combine joins all three lists in the order you listed them. The inner lists can have any number of items, even just one, like the {“Keyboard”} list here.

Example 3: Combine a Column from Two Tables

This one comes up a lot when the same kind of data sits in separate tables. I have January orders in one table and February orders in another, and I want a single list of all the order IDs.

Below is the January table, on the Example 3 – January sheet.

JanOrders table with Order ID and Amount columns for January

And here is the February table, on the Example 3 – February sheet. It has the same two columns.

FebOrders table with Order ID and Amount columns for February

The two tables are Excel Tables named JanOrders and FebOrders. The code below reads them by those names, so for your own data, change the names to match your tables.

Create a new blank query, open the Advanced Editor (Home > Advanced Editor), and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="JanOrders"]}[Content],
Feb = Excel.CurrentWorkbook(){[Name="FebOrders"]}[Content],
AllOrders = List.Combine({Source[Order ID],Feb[Order ID]})
in
AllOrders

Result: ORD-1001, ORD-1002, ORD-1003, ORD-1004, ORD-1005, ORD-1006, ORD-1007

One list of all seven order IDs, January first, then February

Here, the Source step reads the January table and the Feb step reads the February table. Source[Order ID] and Feb[Order ID] each give the Order ID column as a list, and List.Combine joins those two lists.

You get the four January IDs first, then the three February IDs, because that’s the order of the lists inside the curly brackets.

Example 4: Get a Unique List from Two Columns

Joining lists keeps every item, including the repeats. Below are the five bestselling drinks at two cafés, in a Downtown column and an Airport column, and I want a list of every drink that appears, with each drink only once.

CafeBestsellers table with Downtown and Airport columns of drinks

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="CafeBestsellers"]}[Content],
AllItems = List.Distinct(List.Combine({Source[Downtown],Source[Airport]}))
in
AllItems

Result: Latte, Cappuccino, Mocha, Flat White, Americano, Cold Brew, Chai Tea

Seven unique drinks from both cafés after List.Distinct

Here, List.Combine joins the two columns into one list of ten drinks. Latte, Mocha, and Americano appear in both columns, so the List.Distinct function removes the repeats and leaves seven drinks.

The order follows the first time each drink appears, so all the Downtown drinks come first, then Cold Brew and Chai Tea from the Airport column.

Follow along with the example file

List.Combine Function Examples.xlsx

Download

Example 5: Find the Highest Value Across Several Columns

This next one is handy when your numbers are spread across columns. Below is a table of monthly sales for four branches, with one column each for January, February, and March, and I want the single highest monthly sale in the whole table.

BranchSales table with Jan, Feb and Mar sales for four branches

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="BranchSales"]}[Content],
HighestSale = List.Max(List.Combine({Source[Jan],Source[Feb],Source[Mar]}))
in
HighestSale

Result: 24150

List.Max over the combined month columns returns 24150

Here, List.Combine puts all twelve sales values from the three month columns into one list. Then the List.Max function returns the largest value in that list, which is Denver’s March sale.

You can swap List.Max for another list function to get a different answer from the same combined list. For example, the List.Sum function gives the total of all twelve values, and the List.Average function gives the average.

Example 6: Flatten a List of Lists into One List

This is the job List.Combine is best at. Below is a list of support tickets where the Labels column has one or more labels per ticket, separated by a comma and a space, and I want one list of all the labels.

Tickets table with comma-separated labels in each cell

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Tickets"]}[Content],
AllLabels = List.Combine(List.Transform(Source[Labels],each Text.Split(_,", ")))
in
AllLabels

Result: billing, urgent, login, billing, refund, follow-up, shipping, urgent

All eight labels from every ticket in one flat list

Here, the List.Transform function goes through each cell in the Labels column, and the Text.Split function splits the text at every comma and space. The each keyword runs Text.Split once for every cell, and _ stands for the text of the current cell.

That gives a list of four lists, one per ticket, like {“billing”,”urgent”} for the first ticket.

List.Combine then joins those four lists into one flat list of eight labels. You couldn’t easily do this with the & operator, because the number of lists depends on how many rows the table has.

This works because the labels are always separated by a comma followed by a space. If your data uses a different separator, change “, ” in the Text.Split function.

To get each label only once, wrap the formula in List.Distinct, as in Example 4.

Example 7: Nested Lists Stay Nested

There’s one thing List.Combine doesn’t do, and it can catch you out. Suppose the second list you’re joining has another list inside it, like a group of extra sizes.

Create a new blank query and use this formula:

= List.Combine({{"Small","Medium"},{"Large",{"XL","XXL"}}})

Result: Small, Medium, Large, List

The nested list stays as one item, shown as List: Small, Medium, Large, List

Here, you might expect five sizes, but you get four items. List.Combine only joins one level of lists, so the inner list {“XL”,”XXL”} is added as a single item, and Power Query shows it as List.

If you want XL and XXL as separate items, put them straight into one of the lists you’re joining, like {"Large","XL","XXL"}.

Example 8: Build a List of Columns to Keep

Sometimes the list of columns you want to keep changes over time, as new columns get added to the data.

Below is an inventory table with SKU and Product columns, a stock quantity column for each warehouse (Qty North and Qty South), and a Unit Cost column.

I want to keep only SKU, Product, and every column that starts with “Qty”, including any Qty column added later.

Inventory table with SKU, Product, two Qty columns and Unit Cost

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Inventory"]}[Content],
Selected = Table.SelectColumns(Source,List.Combine({
{"SKU","Product"},
List.Select(Table.ColumnNames(Source),each Text.StartsWith(_,"Qty"))
}))
in
Selected

Result: A table with the SKU, Product, Qty North, and Qty South columns

Only SKU, Product and the two Qty columns are kept

Here, the Table.ColumnNames function gives the list of all the column names in the table. The List.Select function keeps only the names that start with “Qty”, and List.Combine joins them with the fixed list {“SKU”,”Product”}.

The Table.SelectColumns function then keeps just those four columns and drops Unit Cost. If a new warehouse column like Qty West is added later, the query picks it up on the next refresh without any change.

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.