使用英语阅读

通过


Table.LastN

语法

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

关于

根据 countOrCondition 的值,返回 table 表的最后一行(或几行):

  • 如果 countOrCondition 是数字,则将返回从末尾 - countOrCondition 位置开始的多行。
  • 如果 countOrCondition 是条件,则将以升序位置返回满足此条件的行,直到行不满足条件为止。

示例 1

查找表的最后两行。

使用情况

Table.LastN(
    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 = 2, Name = "Jim", Phone = "987-6543"],
    [CustomerID = 3, Name = "Paul", Phone = "543-7890"]
})

示例 2

查找表中 [a] > 0 的最后几行。

使用情况

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

输出

Table.FromRecords({
    [a = 3, b = 4],
    [a = 5, b = 6]
})