PowerApps 中的 AddColumns、DropColumns、RenameColumns 和 ShowColumns 函数AddColumns, DropColumns, RenameColumns, and ShowColumns functions in PowerApps

通过添加、删除、重命名和选择来为表造型。Shapes a table by adding, dropping, renaming, and selecting its columns.


以下函数通过调整表的列来为表造型:These functions shape a table by adjusting its columns:

  • 将包含多个列的表缩减为包含一个列,使该表可用于 LowerAbs 等单列函数。Reduce a table that contains multiple columns down to a single column for use with single-column functions, such as Lower or Abs.
  • 将计算结果列(例如,显示“数量”乘以“单价”后的结果的“总价”列)添加到某个表。Add a calculated column to a table (for example, a Total Price column that shows the results of multiplying Quantity by Unit Price).
  • 使用更有意义的名称将列重命名,以便向用户显示或者在公式中使用。Rename a column to something more meaningful, for display to users or for use in formulas.

表是 PowerApps 中的一个值,与字符串或数字类似。A table is a value in PowerApps, just like a string or a number. 可将表指定为公式中的参数,函数可以返回表作为结果。You can specify a table as an argument in a formula, and functions can return a table as a result. 本主题中介绍的函数不会修改表。The functions that this topic describes don't modify a table. 这些函数将表用作参数,并转换一个应用了转换的新表。Instead they take a table as an argument and return a new table with a transform applied. 请参阅使用表,了解更多详情。See working with tables for more details.

无法使用这些函数修改数据源的列。You can't modify the columns of a data source by using these functions. 必须在数据源中修改数据。You must modify the data at its source. 可以使用 Collect 函数将列添加到集合You can add columns to a collection with the Collect function. 有关详细信息,请参阅使用数据源See working with data sources for more details.


AddColumns 函数将列添加到表,某个公式将定义该列中的值。The AddColumns function adds a column to a table, and a formula defines the values in that column. 现有列保持不变。Existing columns remain unmodified.

将会针对表的每条记录计算该公式。The formula is evaluated for each record of the table.

Fields of the record currently being processed are available within the formula. You simply reference them by name as you would any other value. You can also reference control properties and other values from throughout your app. For more details, see the examples below and working with record scope.

DropColumns 函数从表中排除列。The DropColumns function excludes columns from a table. 其他所有列保持不变。All other columns remain unmodified. DropColumns 排除列,ShowColumns 包含列。DropColumns excludes columns, and ShowColumns includes columns.

RenameColumns 函数重命名表的列。The RenameColumns function renames columns of a table. 其他所有列保留其原始名称。All other columns retain their original names.

ShowColumns 函数包含某个表的列并删除其他所有列。The ShowColumns function includes columns of a table and drops all other columns. 可以使用 ShowColumns 从多列表创建单列表。You can use ShowColumns to create a single-column table from a multi-column table. ShowColumns 包含列,DropColumns 排除列。ShowColumns includes columns, and DropColumns excludes columns.

对于所有这些函数,结果是已应用转换的新表。For all these functions, the result is a new table with the transform applied. 不会修改原始表。The original table isn't modified.

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.


AddColumns( Table, ColumnName1, Formula1 [, ColumnName2, Formula2, ... ] )AddColumns( Table, ColumnName1, Formula1 [, ColumnName2, Formula2, ... ] )

  • Table - 必需。Table - Required. 要运算的表。Table to operate on.
  • ColumnName(s) - 必需。ColumnName(s) - Required. 要添加的列的名称。Name(s) of the column(s) to add. 必须为此参数指定字符串(例如 "Name",包括双引号)。You must specify a string (for example, "Name" with double quotes included) for this argument.
  • Formula(s) - 必需。Formula(s) - Required. 要针对每条记录计算的公式。Formula(s) to evaluate for each record. 结果将添加为相应新列的值。The result is added as the value of the corresponding new column. 可在此公式中引用表的其他列。You can reference other columns of the table in this formula.

DropColumns( Table, ColumnName1 [, ColumnName2, ... ] )DropColumns( Table, ColumnName1 [, ColumnName2, ... ] )

  • Table - 必需。Table - Required. 要运算的表。Table to operate on.
  • ColumnName(s) - 必需。ColumnName(s) - Required. 要删除的列的名称。Name(s) of the column(s) to drop. 必须为此参数指定字符串(例如 "Name",包括双引号)。You must specify a string (for example, "Name" with double quotes included) for this argument.

RenameColumns( Table, OldColumneName, NewColumnName )RenameColumns( Table, OldColumneName, NewColumnName )

  • Table - 必需。Table - Required. 要运算的表。Table to operate on.
  • OldColumnName - 必需。OldColumnName - Required. 要重命名的列的名称。Name of the column to rename. 此名称必须是字符串(例如 "Name",包括双引号)。This name must be a string (for example "Name" with double quotes included).
  • NewColumnName - 必需。NewColumnName - Required. 替换后的名称。Replacement name. 必须为此参数指定字符串(例如 "Customer Name",包括双引号)。You must specify a string (for example, "Customer Name" with double quotes included) for this argument.

ShowColumns( Table, ColumnName1 [, ColumnName2, ... ] )ShowColumns( Table, ColumnName1 [, ColumnName2, ... ] )

  • Table - 必需。Table - Required. 要运算的表。Table to operate on.
  • ColumnName(s) - 必需。ColumnName(s) - Required. 要包含的列的名称。Name(s) of the column(s) to include. 必须为此参数指定字符串(例如 "Name",包括双引号)。You must specify a string (for example, "Name" with double quotes included) for this argument.


本部分中的示例使用 IceCreamSales 数据源,其中包含下表中的数据:The examples in this section use the IceCreamSales data source, which contains the data in this table:

这些示例都不会修改 IceCreamSales 数据源。None of these examples modify the IceCreamSales data source. 每个函数将数据源的值转换为表,然后返回该值作为结果。Each function transforms the value of the data source as a table and returns that value as the result.

公式Formula 说明Description 结果Result
AddColumns( IceCreamSales, "Revenue", UnitPrice * QuantitySold )AddColumns( IceCreamSales, "Revenue", UnitPrice * QuantitySold ) Revenue 列添加到结果。Adds a Revenue column to the result. 对于每条记录,将计算 UnitPrice * QuantitySold,并将结果放在新列中。For each record, UnitPrice * QuantitySold is evaluated, and the result is placed in the new column.
DropColumns( IceCreamSales, "UnitPrice" )DropColumns( IceCreamSales, "UnitPrice" ) 从结果中排除 UnitPrice 列。Excludes the UnitPrice column from the result. 使用此函数可排除列,使用 ShowColumns 可包含列。Use this function to exclude columns, and use ShowColumns to include them.
ShowColumns( IceCreamSales, "Flavor" )ShowColumns( IceCreamSales, "Flavor" ) 仅在结果中包含 Flavor 列。Includes only the Flavor column in the result. 使用此函数可包含列,使用 DropColumns 可排除列。Use this function include columns, and use DropColumns to exclude them.
RenameColumns( IceCreamSales, "UnitPrice", "Price")RenameColumns( IceCreamSales, "UnitPrice", "Price") 在结果中将 UnitPrice 列重命名。Renames the UnitPrice colum in the result.
AddColumns( IceCreamSales, "Revenue",
UnitPrice * QuantitySold ),
"UnitPrice", "Price" ),
"Quantity" )
AddColumns( IceCreamSales, "Revenue",
UnitPrice * QuantitySold ),
"UnitPrice", "Price" ),
"Quantity" )
从公式内部开始,按顺序执行以下表转换:Performs the following table transforms in order, starting from the inside of the formula:
  1. 根据针对每条记录计算 UnitPrice * Quantity 后的结果添加 Revenue 列。Adds a Revenue column based on the per-record calculation of UnitPrice * Quantity.
  2. UnitPrice 重命名为 PriceRenames UnitPrice to Price.
  3. 排除 Quantity 列。Excludes the Quantity column.
请注意,顺序很重要。Note that order is important. 例如,不能在重命名 UnitPrice 后计算该列。For example, we can't calculate with UnitPrice after it has been renamed.

分步操作Step by step

  1. 导入或创建一个名为 Inventory 的集合,作为在库中显示图像和文本中所述的第一个子过程。Import or create a collection named Inventory as the first subprocedure in Show text and images in a gallery describes.
  2. 添加一个按钮,然后将其 OnSelect 属性设置为以下公式:Add a button, and set its OnSelect property to this formula:

    ClearCollect(Inventory2, RenameColumns(Inventory, "ProductName", "JacketID"))ClearCollect(Inventory2, RenameColumns(Inventory, "ProductName", "JacketID"))

  3. 按 F5,选择刚刚创建的按钮,然后按 Esc 返回设计工作区。Press F5, select the button that you just created, and then press Esc to return to the design workspace.
  4. 在“文件”菜单中选择“集合”。On the File menu, select Collections.
  5. 确认已创建名为 Inventory2 的集合。Confirm that you've created a collection, named Inventory2. 新集合包含的信息与 Inventory 相同,不过,Inventory 中名为 ProductName 的列在 Inventory2 中名为 JacketIDThe new collection contains the same information as Inventory except that the column named ProductName in Inventory is named JacketID in Inventory2.