Latest Posts

PowerApps Count rows in table or collection


The CountRows function in Power Apps is used to count the number of rows in a table or collection. This function is particularly useful for determining the size of a dataset, performing conditional logic based on the number of records, or displaying counts to users.

PowerApps – CountRows() function Syntax

CountRows(Table)

  • Table: The table or collection for which you want to count the number of rows.

Notes:

  1. Delegation: Be mindful of delegation limits when using CountRows with large data sources. Ensure that your formulas are delegable to handle large datasets efficiently.
  2. Performance: For large datasets, consider using indexed data sources or applying filters to reduce the number of rows before counting.
  3. Error Handling: Handle cases where the count might be zero to avoid displaying misleading information or causing errors in the app.

PowerApps - Counting Rows in a Collection

Suppose you have a collection named Products and you want to count the number of rows in this collection.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Count the Number of Rows:
    • Add a Label control.
    • Set the Text property of the Label to:

 

CountRows(Products)

This will display the number of rows in the Products collection, which is 3.

PowerApps - Count Rows in a Data Source

Suppose you have a SharePoint list named Employees and you want to count the number of rows in this list.

  1. Connect to the SharePoint List:
    • In Power Apps, go to the Data tab.
    • Add a data source and connect to your SharePoint site and list (Employees).
  2. Count the Number of Rows:
    • Add a Label control.
    • Set the Text property of the Label to:

CountRows(Employees)

This will display the number of rows in the Employees SharePoint list.

PowerApps - Count Rows After Filtering

You can use CountRows in combination with the Filter function to count the number of rows that meet certain criteria.

  1. Count Filtered Rows:
    • Add a Label control.
    • Set the Text property of the Label to:

CountRows(Filter(Products, Price > 400))

This will count the number of products with a price greater than 400, which in this case is 2.

PowerApps - Use CountRows for Dynamic UI

You can use CountRows to dynamically update the user interface based on the number of records.

  1. Show/Hide a Control Based on the Number of Rows:
    • Add a Button control.
    • Set the Visible property of the Button to:

CountRows(Products) > 0

This will make the button visible only if there are one or more rows in the Products collection.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint