Table.RemoveFirstN

Table.RemoveFirstN is a Power Query M function that removes a specified number or condition-matching rows from the beginning of a table. The function returns a new table with the rows removed according to the countOrCondition parameter.

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

Syntax

Table.RemoveFirstN(
   table as table,
   optional countOrCondition as any,
) as table

Description

Returns a table that does not contain the first specified number of rows, countOrCondition, of the table table. The number of rows removed depends on the optional parameter countOrCondition.

  • If countOrCondition is omitted only the first row is removed.
  • If countOrCondition is a number, that many rows (starting at the top) will be removed.
  • If countOrCondition is a condition, the rows that meet the condition will be removed until a row does not meet the condition.

Examples

Remove the first row of the table.

Table.RemoveFirstN( 
    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"]
    } ),
    1
 )

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

Remove the first two rows of the table.

Table.RemoveFirstN( 
    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"]
    } ),
    2
 )

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

Remove the first rows where [CustomerID] <=2 of the table.

Table.RemoveFirstN( 
    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"]
} )
 */ 

Other functions related to Table.RemoveFirstN are:

BI Gorilla Youtube Channel

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