共用方式為


Table.RemoveFirstN

語法

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

關於

傳回資料表,其不包含資料表 table 第一個指定的資料列數目 countOrCondition。 已移除的資料列數目,取決於 countOrCondition 的選擇性參數。

  • 如果省略 countOrCondition,則只會移除第一個資料列。
  • 如果 countOrCondition 是數字,則會移除多個資料列 (從頂端開始)。
  • 如果 countOrCondition 是條件,就會移除符合該條件的資料列,直到資料列不符合條件為止。

範例 1

移除資料表的第一個資料列。

使用方式

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
)

輸出

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

範例 2

移除資料表的前兩個資料列。

使用方式

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
)

輸出

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

範例 3

移除資料表中 [CustomerID] <=2 的前幾個資料列。

使用方式

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
)

輸出

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