Downloads
Power Query MTable: rowsBeginner

Table.RemoveFirstN

Removes the first rows, by a count or until a test stops being true.

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

Returns: A table without the first rows.

What it does

Table.RemoveFirstN drops the rows at the top of a table and keeps the rest. Accounting exports often begin with a company name, a report title and some blank lines. This step removes that preamble so the real header row can become the column names.

Syntax and arguments

Example

A bank export starts with four rows of report information. The first four rows are removed, and the next row becomes the header.

let
    Source = Excel.CurrentWorkbook(){[Name = "Bank"]}[Content],
    NoPreamble = Table.RemoveFirstN(Source, 4),
    Headers = Table.PromoteHeaders(NoPreamble, [PromoteAllScalars = true])
in
    Headers

The count is the number of rows, not a column value. Check the top of the file before you choose the number. A number that is too high also removes real transactions.

Example: a second, different use

When the number of title rows can change from month to month, use a condition. Rows are removed from the top while the Date column is blank.

let
    Source = Excel.CurrentWorkbook(){[Name = "Bank"]}[Content],
    NoPreamble = Table.RemoveFirstN(Source, each [Date] = null)
in
    NoPreamble

Things to watch

In business terms

Bank statements, aged trial balances and payroll registers all come with headings above the data. Removing the preamble consistently is the first step in building a file that can be refreshed each month without manual editing.

Related functions

All Power Query M functions · View as Markdown · M basics