List.Combine

Updated on

List.Combine is a Power Query M function that takes a list of lists and merges them into one new list. The function returns a single list containing the elements from all input lists.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

List.Combine( lists as list ) as list

Description

The List.Combine function merges multiple lists into a single list. By taking a list of lists as input, it produces a consolidated list with the contents of each inner list sequenced consecutively.

Examples

Let’s look at a few examples of how you can use the List.Combine Function.

Combining Numbers

Consider two lists of numbers: one with {10, 11} and the other with {12, 13}. You might wonder, “How can I merge these two?” The List.Combine function offers an easy method.

Using the function, the merging process is as simple as:

List.Combine( { {10, 11}, { 12, 13 } } ) // Output: { 10, 11, 12, 13 }

Did you know there’s another method? You can also merge these lists with the combination operator &:

 { 10, 11} & { 12, 13 } 

Combine Different Types of Values

Merging isn’t confined to just identical data types. You can bring together different types of values, as well. For instance, let’s explore the scenario where you wish to combine a numerical list {1, 2} with a textual list {“a”, “b”}:

List.Combine( { {1, 2}, {"a", "b"} } ) // Output: { 1, 2, "a", "b" }

Taking it a notch higher, you might come across situations where you need to blend standard lists with nested ones. Let’s see that in action:

 // Output: { 1, 2, "a", {"#", "@"} }
List.Combine( 
  {
    {1, 2}, 
    {"a", {"#", "@"} } 
  } 
)

If the above feels a tad intricate, you can also use variables. Breaking the code down step by step can improve understanding. Here’s an alternative representation:

 // Output: { 1, 2, "a", {"#", "@"} }
let 
  List1 = { 1, 2 },
  List2 = {"a", {"#", "@"} } ,
  Combined = List.Combine( { List1, List2 } )
in
  Combined

Learn more about List.Combine in the following articles:

Other functions related to List.Combine are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/list-combine

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy