Power Query List.Combine: Step-by-Step Guide
In this article
List.Combine in Power Query takes a list of lists and merges them into a single flat list. It does not remove duplicates or change data types; it simply concatenates the inner lists in the order they appear. You need Power Query Editor open in Excel or Power BI and at least two lists to combine.
What You'll Need
- Power Query Editor open in Excel (Data > Get & Transform Data > Launch Power Query Editor) or Power BI Desktop (Home > Transform data). Menu labels can differ slightly by version or region.
- Two or more lists to combine. These can be existing queries, typed lists, or columns containing lists.
- Basic familiarity with the Power Query formula bar and the Advanced Editor.
Step-by-Step
- Open the Power Query Editor. In Excel, go to Data > Get & Transform Data > Launch Power Query Editor. In Power BI Desktop, go to Home > Transform data. The editor opens with your existing queries or a blank workspace.
- Create or identify the lists you want to combine. If you already have queries that return lists, note their names. If not, you can create lists manually using the formula bar. For example, type
= {1, 2, 3}in a new blank query to create a list of numbers, or= {"A", "B"}for text. - Create a new blank query to hold the combined result. In the Home tab, click New Source > Blank Query. This opens the Power Query formula bar where you will write the List.Combine expression.
- Write the List.Combine formula. In the formula bar, type = List.Combine({List1, List2}) where List1 and List2 are the names of your existing list queries. If you are using literal lists, you can nest them directly: .
- Press Enter to evaluate the formula. Power Query will return a single list containing all elements from the inner lists in order. For example, returns {1, 2, 3, 4} .
- Convert the list to a table if needed. If you want to work with the result as a table, go to the Transform tab and click To Table. In the dialog, accept the default or choose a delimiter, then click OK. You can then rename the column and continue transforming.
- Rename the query for clarity. Right-click the query in the Queries pane and select Rename, or press F2. Give it a descriptive name like "CombinedList".
- Load the result. In Excel, go to Home > Close & Load to load the query to a worksheet or the Data Model. In Power BI, go to Home > Close & Apply to load the data into the model.
Common Mistakes
- Passing a single list instead of a list of lists. List.Combine expects its argument to be a list where each element is itself a list. If you pass
{1, 2, 3}, you will get an error because the elements are numbers, not lists. - Forgetting curly braces around query names. When combining existing queries, you must wrap the query names in curly braces:
List.Combine({Query1, Query2}). WritingList.Combine(Query1, Query2)is invalid syntax. - Assuming duplicates are removed. List.Combine does not remove duplicates. If you need unique values, wrap the result in
List.Distinct:List.Distinct(List.Combine({List1, List2})). - Mixing data types. Combining lists of different types (e.g., numbers and text) is allowed but may cause issues later. Ensure the resulting list has a consistent type or handle conversions explicitly.
- Using the wrong case. Power Query functions are case-sensitive. Use
List.Combine, notlist.combine.
Tips
- You can combine more than two lists by adding them to the list argument:
List.Combine({List1, List2, List3}). - If you have a column of lists in a table, you can combine all lists in that column using
List.Combine(TableColumn[ColumnName]). - Use the Advanced Editor (Home > Advanced Editor) to view and edit the full M code for complex combinations.
- To preserve the order of elements, List.Combine processes inner lists from first to last. If order matters, ensure your input lists are ordered correctly.
- Combine with
List.Transformto convert elements before flattening, e.g.,List.Combine(List.Transform(MyList, each {_})).
Troubleshooting
- Error: "We cannot convert a value of type Number to type List." This means you passed a list of numbers instead of a list of lists. Check that each element in the argument is a list. Use instead of List.Combine({1, 2, 3, 4}) .
- Error: "The name 'List1' wasn't recognized." Ensure the query name is spelled correctly and exists in the Queries pane. Query names are case-sensitive.
- Result is empty. Check that the inner lists are not empty. If all inner lists are empty, the result will be an empty list.
- Unexpected order. List.Combine preserves the order of the inner lists as they appear in the argument. If you need a different order, reorder the inner lists before combining.
- Performance issues with large lists. Combining very large lists can be slow. Consider filtering or reducing data before combining.
Frequently Asked Questions
What does List.Combine do?
It takes a list of lists and returns a single list containing all elements from the inner lists, in order.
Does List.Combine remove duplicates?
No. Use List.Distinct after combining if you need unique values.
Can I combine lists from different queries?
Yes. Reference the query names inside curly braces: List.Combine({Query1, Query2}).
How do I combine a column of lists in a table?
Use List.Combine(TableName[ColumnName]) to combine all lists in that column.
What is the difference between List.Combine and List.Union?
List.Combine concatenates lists and keeps duplicates. List.Union also concatenates but removes duplicates.
Can I combine more than two lists?
Yes. Add more lists to the argument: List.Combine({List1, List2, List3}).