Table.RemoveLastN

Składnia

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

Około

Zwraca tabelę, która nie zawiera ostatnich countOrCondition wierszy tabeli table. Liczba usuniętych wierszy zależy od opcjonalnego parametru countOrCondition.

  • Jeśli countOrCondition zostanie pominięty, zostanie usunięty tylko ostatni wiersz.
  • Jeśli countOrCondition jest liczbą, zostanie usunięta dokładnie taka liczba wierszy (począwszy od dołu).
  • Jeśli countOrCondition jest warunkiem, wiersze spełniające warunek zostaną usunięte, dopóki wiersz nie spełnia warunku.

Przykład 1

Usuń ostatni wiersz tabeli.

Użycie

Table.RemoveLastN(
    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
)

Wyjście

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

Przykład 2

Usuń ostatnie wiersze w tabeli, gdzie [CustomerID] to > 2.

Użycie

Table.RemoveLastN(
    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
)

Wyjście

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