List.Zip

D

T

The M Code Behind the Power Query M function List.Zip

What is List.Zip Function?

List.Zip is a M function in Power Query that takes two lists as input and zips them together into a single list of records. The two lists must have the same number of elements. The resulting list of records will have a record for each pair of elements in the input lists. The first element of the first list will be paired with the first element of the second list, the second element of the first list will be paired with the second element of the second list, and so on.

How to Use List.Zip Function?

To use the List.Zip function, you need to pass two lists as arguments. Here is an example:


let

List1 = {1, 2, 3},

List2 = {“A”, “B”, “C”},

ZipList = List.Zip({List1, List2})

in

ZipList


In this example, we have two lists: List1 with elements 1, 2, and 3, and List2 with elements "A", "B", and "C". We then call the List.Zip function and pass it the two lists as arguments using the curly braces syntax { }. The result of this function call is a single list of records:


{[Column1=1,Column2=”A”],[Column1=2,Column2=”B”],[Column1=3,Column2=”C”]}


As you can see, the resulting list of records has three elements, one for each pair of elements in the input lists.

The M Code Behind List.Zip Function

The M code behind the List.Zip function is relatively simple. Here is what it looks like:


(List1 as list, List2 as list) =>

let

ZipList = List.Zip({List1, List2}),

CombineRecords = (Value1, Value2) => [Column1=Value1, Column2=Value2]

in

List.Transform(ZipList, each CombineRecords(_{0}, _{1}))


The List.Zip function takes two lists (List1 and List2) as input arguments. It then uses the List.Zip function to zip the two lists together into a single list of records (ZipList). The CombineRecords function is defined to create a new record for each pair of elements in the input lists. The resulting list of records is created using the List.Transform function, which applies the CombineRecords function to each element of the ZipList.

In conclusion, the List.Zip function is a powerful tool for combining two lists into a single list of records. The M code behind this function is relatively simple and can be easily modified to suit your specific needs. Understanding the M code behind this function will help you to better understand how Power Query works and how you can use it to transform and analyze your data.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)