Table.ToRows

Updated on

Table.ToRows is a Power Query M function that creates a list of nested lists from a table, where each list item is an inner list that contains the row values. The function returns a list of lists representing the rows and their respective values.

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

Syntax

Table.ToRows( table as table ) as list

Description

Table.ToRows creates a list of nested lists of row values from a table. Each list item is an inner list containing the row values from table.

Examples

Let’s have a look at how the Table.ToRows function works.

If you’re working with a table, you may run into a scenario where you want to access the table row values as a list. The easiest way to store row values in a list is by using the Table.ToRows function. For instance, take this expression:

Table.ToRows( Source )

If you apply this on the source table (depicted at the top of below image), the result is a list of lists. Here each list contains the row values from the table.

Table.ToRows stores table row values within a list in Power Query M

You can try this yourself by using the following code:

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 }
      }
    ),
    TableToRows = Table.ToRows( Source )
in
    TableToRows

Other functions related to Table.ToRows are:

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

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