Record.ToList

D

T

The M Code Behind the Power Query M function Record.ToList

What is a Record in Power Query M?

In Power Query M, a record is a data type that consists of a set of named values. Each value in a record is associated with a unique name, and the values can be of different data types such as text, numbers, dates, and so on. Records can be created using the Record.FieldValues function or by using the curly brace notation.

What is the Record.ToList Function?

The Record.ToList function is used to convert a record into a list of values. This function takes a record as its argument and returns a list of values in the order they were defined in the record. The values in the list can be of any data type, and they are not associated with any names.

How to Use the Record.ToList Function?

To use the Record.ToList function in Power Query M, you need to provide a record as its argument. The following code snippet shows how to use this function:


let

myRecord = [Name = “John”, Age = 30, Sex = “Male”],

myList = Record.ToList(myRecord)

in

myList


In this code snippet, we define a record called "myRecord" with three fields: Name, Age, and Sex. We then use the Record.ToList function to convert this record into a list of values and assign it to a variable called "myList". Finally, we return the "myList" variable.

The output of this code snippet is as follows:


{“John”, 30, “Male”}


As you can see, the record has been converted into a list of values in the order they were defined in the record.

Why Use the Record.ToList Function?

The Record.ToList function is a powerful tool that can be used to manipulate data in Power Query M. It can be used to convert a record into a list of values, which can then be filtered, sorted, or transformed using other functions. For example, you can use the List.Select function to filter the list based on certain criteria, or the List.Sort function to sort the list in ascending or descending order.

The Record.ToList function can also be used to create a dynamic list of values based on the contents of a record. For example, if you have a record with a variable number of fields, you can use the Record.ToList function to create a list of values that contains only the fields that are present in the record. You can then use this list to perform various transformations on the data.

The Record.ToList function is an important tool in Power Query M that allows users to convert a record into a list of values. This function can be used to manipulate data in a variety of ways, such as filtering, sorting, and transforming. By understanding the M code behind this function, you can take full advantage of its capabilities and create powerful data transformations in Power Query M.

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)