PowerApps 中的 Count、CountA、CountIf 和 CountRows 函数Count, CountA, CountIf, and CountRows functions in PowerApps

中所有记录计数,或对所有满足条件的记录计数。Counts all records in a table, or counts all records that satisfy a condition.

说明Description

Count 函数对包含单列表中数值的记录数目进行计数。The Count function counts the number of records that contain a number in a single-column table.

CountA 函数对单列表中不为空白的记录数进行计数。The CountA function counts the number of records that aren't blank in a single-column table. 此函数包括计数中的空白文本 ("")。This function includes empty text ("") in the count.

CountIf 函数对表中逻辑公式为 true 的记录数进行计数。The CountIf function counts the number of records in a table that are true for a logical formula. 该公式可以引用表的The formula can reference columns of the table.

CountRows 函数对表中的记录数进行计数。The CountRows function counts the number records in a table.

这些函数每一个都会返回一个数值。Each of these functions returns a number.

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

Count( SingleColumnTable )Count( SingleColumnTable )
CountA( SingleColumnTable ) CountA( SingleColumnTable )

  • SingleColumnTable - 必需。SingleColumnTable - Required. 要计数的记录的列。Column of records to count.

CountIf( Table, LogicalFormula )CountIf( Table, LogicalFormula )

  • Table - 必需。Table - Required. 要计数的记录的表。Table of records to count.
  • LogicalFormula - 必需。LogicalFormula - Required. 用于对表中每条记录求值的公式。Formula to evaluate for each record of the table. 对此公式返回 true 的记录进行计数。Records that return true for this formula are counted. 该公式可以引用表的列。The formula can reference columns of the table.

CountRows( Table )CountRows( Table )

  • Table - 必需。Table - Required. 要计数的记录的表。Table of records to count.

示例Example

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

    CountIf(Inventory, UnitsInStock < 30)CountIf(Inventory, UnitsInStock < 30)

    标签显示为 2,因为有两种产品(Ganymede 和 Callisto)的库存量小于 30 套。The label shows 2 because two products (Ganymede and Callisto) have fewer than 30 units in stock.

  3. 添加另一个标签,然后将其 Text 属性设置为以下公式:Add another label, and set its Text property to this formula:

    CountA(Inventory.UnitsInStock)CountA(Inventory.UnitsInStock)

    标签显示为 5,表示 UnitsInStock 列中非空单元格的数目。The label shows 5, the number of non-empty cells in the UnitsInStock column.

  4. 添加另一个标签,然后将其 Text 属性设置为以下公式:Add another label, and set its Text property to this formula:

    CountRows(Inventory)CountRows(Inventory)

    标签显示为 5,因为该集合包含 5 行。The label shows 5 because the collection contains five rows.