Table.SelectRows

Table.SelectRows is a Power Query M function that filters rows in a table based on a specified selection condition. The function returns a table with the rows that match the selection condition.

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

Syntax

Table.SelectRows(
   table as table,
   condition as function,
) as table

Description

Returns a table of rows from the table, that matches the selection condition.

Examples

Select the rows in the table where the values in [CustomerID] column are greater than 2.

Table.SelectRows( 
    Table.FromRecords( {
        [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
        [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
        [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
        [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
    } ),
    each [CustomerID] > 2
 )

 /* Output: 
Table.FromRecords( {
    [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
    [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
} )
 */ 

Select the rows in the table where the names do not contain a “B”.

Table.SelectRows( 
    Table.FromRecords( {
        [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
        [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
        [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
        [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
    } ),
    each not Text.Contains( [Name], "B" )
 )

 /* Output: 
Table.FromRecords( {
    [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
    [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
    [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
} )
 */ 

Other functions related to Table.SelectRows are:

BI Gorilla Blog

Last update: August 28, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-selectrows
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.