Table.ToList

D

T

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

What is the Table.ToList function?

The Table.ToList function is a Power Query M function that is used to convert a table into a list. In other words, it takes the contents of a table and returns a list of records, where each record represents a row in the original table. The syntax for the Table.ToList function is as follows:


Table.ToList(table as table) as list


The function takes a single parameter, which is the table to be converted. The result is a list of records, where each record contains a set of name/value pairs that correspond to the columns in the original table.

How does the Table.ToList function work?

The Table.ToList function works by iterating over the rows in the input table and appending each row to a list. The resulting list is a collection of records, where each record represents a row in the original table. The name/value pairs in each record correspond to the column names and cell values in the original table.

Here’s an example of how the Table.ToList function can be used:


let

Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

Result = Table.ToList(Source)

in

Result


In this example, the Table.ToList function is applied to a table named “Table1” in the current workbook. The result is a list of records, where each record represents a row in the original table.

Benefits of using the Table.ToList function

The Table.ToList function has several benefits that make it a useful tool for data transformations. These benefits include:

1. Simplifying data transformations

The Table.ToList function simplifies data transformations by converting a table into a list of records. This makes it easier to work with the data in Power Query, as lists are a common data structure that can be easily manipulated using M functions.

2. Improved performance

The Table.ToList function can improve performance by reducing the number of steps required to perform a data transformation. By converting a table into a list, we can eliminate the need to iterate over each row in the table, reducing the number of operations required to transform the data.

3. Easier to analyze data

Converting a table into a list of records can make it easier to analyze the data in Power Query. Lists can be easily sorted, filtered, and aggregated using a range of M functions, making it easier to gain insights into the data.

The Table.ToList function is a useful tool for data transformations in Power Query. It simplifies the process of converting a table into a list of records, making it easier to work with and analyze the data. By understanding the M code behind the function, we can gain a deeper understanding of how it works and how it can be used to streamline our data transformations.

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)