Table.FirstN
This function retrieves the initial row(s) from the specified table based on the countOrCondition value. When countOrCondition is a numerical value, it returns that quantity of rows from the top of th...
This function retrieves the initial row(s) from the specified table based on the countOrCondition value. When countOrCondition is a numerical value, it returns that quantity of rows from the top of the table. In the case where countOrCondition represents a condition, the function will return rows that satisfy the condition until a row fails to meet the condition.
Retrieve the initial two rows from the provided table using Power Query M as shown in the examples below:
Example 1:
To obtain the first two rows of the table containing Customer information, execute the following script:
```Power Query M
Table.FirstN(
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"]
}),
2)
```
The output will consist of the first two rows of the table:
```Output
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"]
})
```
Example 2:
To identify the first rows where the value in column [a] is greater than 0 in the provided table, utilize the code snippet below:
```Power Query M
Table.FirstN(
Table.FromRecords({
[a = 1, b = 2],
[a = 3, b = 4],
[a = -5, b = -6]
}),
each [a] > 0)
```
The result will display the rows where