Table.FirstN

構文

Table.FirstN(table as table, countOrCondition as any) as table

バージョン情報

countOrCondition の値に応じて、テーブル table の先頭行が返されます。

  • countOrCondition が数の場合は、(先頭から) その数の行が返されます。
  • countOrCondition が条件の場合は、その条件を満たす行が、条件を満たさない行まで返されます。

例 1

テーブルの先頭の 2 行を探します。

使用方法

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
)

出力

Table.FromRecords({
    [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
    [CustomerID = 2, Name = "Jim", Phone = "987-6543"]
})

例 2

テーブル内の [a] > 0 である先頭行を探します。

使用方法

Table.FirstN(
    Table.FromRecords({
        [a = 1, b = 2],
        [a = 3, b = 4],
        [a = -5, b = -6]
    }),
    each [a] > 0
)

出力

Table.FromRecords({
    [a = 1, b = 2],
    [a = 3, b = 4]
})