PowerApps 中的 Remove 與 RemoveIf 函式Remove and RemoveIf functions in PowerApps

移除資料來源中的記錄Removes records from a data source.

說明Description

Remove 函式Remove function

使用 Remove 函式來移除資料來源中的一或多筆特定記錄。Use the Remove function to remove a specific record or records from a data source.

集合中,整筆記錄必須相符。For collections, the entire record must match. 您可以使用 All 引數來移除記錄的所有複本;否則系統只會移除一個記錄複本。You can use the All argument to remove all copies of a record; otherwise, only one copy of the record is removed.

RemoveIf 函式RemoveIf function

使用 RemoveIf 函式,根據一個或一組條件來移除一或多筆記錄。Use the RemoveIf function to remove a record or records based on a condition or a set of conditions. 每個條件可以是任何會產生 truefalse 的公式,而且可以依名稱來參考資料來源的資料行Each condition can be any formula that results in a true or false and can reference columns of the data source by name. 系統會針對每一筆記錄個別評估每個條件,如果所有條件都評估為 true,便會移除該記錄。Each condition is evaluated individually for each record, and the record is removed if all conditions evaluate to true.

RemoveRemoveIf 都會以資料表形式來傳回已修改的資料來源。Remove and RemoveIf return the modified data source as a table. 您只能在行為公式中使用這兩個函式。You can use both functions only in behavior formulas.

您也可以使用 Clear 函式來移除資料來源中的所有記錄。You can also use the Clear function to remove all of the records in a data source.

委派Delegation

When used with a data source, these functions can't be delegated. Only the first portion of the data source will be retrieved and then the function applied. The result may not represent the complete story. A blue dot will appear at authoring time to remind you of this limitation and to suggest switching to delegable alternatives where possible. For more information, see the delegation overview.

語法Syntax

Remove( DataSource, Record1 [, Record2, ... ] [, All ] )Remove( DataSource, Record1 [, Record2, ... ] [, All ] )

  • DataSource – 必要項目。DataSource – Required. 包含您要移除之一或多筆記錄的資料來源。The data source that contains the record or records that you want to remove.
  • Record(s) – 必要項目。Record(s) – Required. 要移除的一或多筆記錄。The record or records to remove.
  • All – 選擇性項目。All – Optional. 在集合中,相同的記錄可能出現多次。In a collection, the same record may appear more than once. 您可以新增 All 引數來移除記錄的所有複本。You can add the All argument to remove all copies of the record.

Remove( DataSource, Table [, All ] )Remove( DataSource, Table [, All ] )

  • DataSource – 必要項目。DataSource – Required. 包含您要移除之記錄的資料來源。The data source that contains the records that you want to remove.
  • Table – 必要項目。Table – Required. 要移除之記錄的資料表。A table of records to remove.
  • All – 選擇性項目。All – Optional. 在集合中,相同的記錄可能出現多次。In a collection, the same record may appear more than once. 您可以新增 All 引數來移除記錄的所有複本。You can add the All argument to remove all copies of the record.

RemoveIf( DataSource, Condition [, ... ] )RemoveIf( DataSource, Condition [, ... ] )

  • DataSource – 必要項目。DataSource – Required. 包含您要移除之一或多筆記錄的資料來源。The data source that contains the record or records that you want to remove.
  • Condition(s) – 必要項目。Condition(s) – Required. 對於要移除的一或多筆記錄會評估為 true 的公式。A formula that evaluates to true for the record or records to remove. 您可以在公式中使用 DataSource 的資料行名稱。You can use column names from the DataSource in the formula. 如果您指定多個條件,這些條件全都必須評估為 true 才能移除該一或多筆記錄。If you specify multiple Conditions, all must evaluate to true for the record or records to be removed.

範例Examples

在這些範例中,您會對名為 IceCream 且開頭為此資料表資料的一或多筆資料來源記錄進行移除︰In these examples, you'll remove a record or records in a data source that's named IceCream and that starts with the data in this table:

公式Formula 說明Description 結果Result
Remove( IceCream,
First( Filter( IceCream, Flavor="Chocolate" ) ) )
Remove( IceCream,
First( Filter( IceCream, Flavor="Chocolate" ) ) )
移除資料來源中的 Chocolate 記錄。Removes the Chocolate record from the data source.

IceCream 資料來源已修改。The IceCream data source has been modified.
Remove( IceCream,
First( Filter( IceCream, Flavor="Chocolate" ) ) First( Filter( IceCream, Flavor="Strawberry" ) ) )
Remove( IceCream,
First( Filter( IceCream, Flavor="Chocolate" ) ) First( Filter( IceCream, Flavor="Strawberry" ) ) )
從資料來源中移除兩筆記錄。Removes two records from the data source.

IceCream 資料來源已修改。The IceCream data source has been modified.
RemoveIf( IceCream, Quantity > 150 )RemoveIf( IceCream, Quantity > 150 ) 移除 Quantity 大於 150 的記錄。Removes records that have a Quantity that's greater than 150.

IceCream 資料來源已修改。The IceCream data source has been modified.
RemoveIf( IceCream, Quantity > 150, Left( Flavor, 1 ) = "S" )RemoveIf( IceCream, Quantity > 150, Left( Flavor, 1 ) = "S" ) 移除 Quantity 大於 150 且 Flavor 開頭為 S 的記錄。Removes records that have a Quantity that's greater than 150 and Flavor starts with an S.


IceCream 資料來源已修改。The IceCream data source has been modified.
RemoveIf( IceCream, true )RemoveIf( IceCream, true ) 從資料來源中移除所有記錄。Removes all records from the data source.

IceCream 資料來源已修改。The IceCream data source has been modified.

逐步解說Step by step

  1. 匯入或建立名為 Inventory 的集合,並如在資源庫中顯示資料所述,將該集合顯示在資源庫中。Import or create a collection named Inventory, and show it in a gallery as Show data in a gallery describes.
  2. 在資源庫中,將影像的 OnSelect 屬性設定為下列運算式:In the gallery, set the OnSelect property of the image to this expression:
    Remove(Inventory, ThisItem)Remove(Inventory, ThisItem)
  3. 按 F5 鍵,然後選取資源庫中的影像。Press F5, and then select an image in the gallery.
    該項目就會從資源庫和集合中移除。The item is removed from the gallery and the collection.