Table.ToRecords

Updated on

Table.ToRecords is a Power Query M function that converts a table to a list of records. The function returns a list of records representing the rows of the table.

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

Syntax

Table.ToRecords( table as table ) as list

Description

Table.ToRecords converts the given table, table, into a list of records, with each table row becoming a record.

Examples

Let’s explore an example to see how the Table.ToRecords function works.

Example Scenario

Suppose you have a table with four columns. There may be situations where you need to convert this table into a different structure for further operations. Specifically, you may want to turn each table row into a record.

The Table.ToRecords function does this by transforming each row into a record and then returning a list of these records. For instance, if you have a table called Source, you can convert it to a list of records as follows:

Table.ToRecords( Source )

You can find both the source table and the resulting table in below image.

Table.ToRecords stores table row values into a record in Power Query M

As the image shows, each row is now represented by a record and their values are stored within it.

Try It Yourself: Sample Code

To see this in action, you can try the following code in the Power Query advanced editor:

let
  Source = 
    #table(
      type table[ProductKey = Int64.Type, Product = Text.Type, OrderDate = Date.Type, Sales = Int64.Type ],
      {
          { 1, "Product A", #date(2024, 1, 15), 150 },
          { 2, "Product B", #date(2024, 2, 20), 200 },
          { 3, "Product C", #date(2024, 3, 10), 175 },
          { 4, "Product D", #date(2024, 4, 25), 220 },
          { 5, "Product E", #date(2024, 5, 5 ), 185 },
          { 6, "Product F", #date(2024, 6, 15), 240 }
      }
    ),
    TableToRecords = Table.ToRecords( Source )
in
    TableToRecords

Learn more about Table.ToRecords in the following articles:

Other functions related to Table.ToRecords are:

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

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