PowerApps CountRows function with Examples

In this PowerApps Tutorial, We will discuss what is PowerApps CountRows function, What is its syntax. Also, By taking some simple scenarios, We will see how a user can use it in the PowerApps.

Also, We will discuss about these below topics that are related to PowerApps CountRows() function as:

  • PowerApps CountRows function
  • PowerApps CountRows function Syntax
  • PowerApps countrows filter
  • PowerApps countrows delegation sharepoint
  • PowerApps countrows sharepoint list
  • PowerApps countrows alternative
  • PowerApps countrows gallery or PowerApps count rows in gallery
  • PowerApps countrows datatable
  • PowerApps countrows collection

PowerApps CountRows function

  • PowerApps CountRows function helps to count the total number of items or records either in a table, SharePoint list, or a gallery control.
  • This PowerApps CountRows function always returns a number value.
  • If you use CountRows functions with filters, then there will be a 50K delegation limit. There is no hard limit on the CountRows function when extracted directly from the data source because of the cached count that Dataverse keeps.
  • When you are using the PowerApps CountRows() function without filtering, then the count might not be 100% accurate, because the cached count updates periodically.

PowerApps CountRows function Syntax

Below represents the syntax for PowerApps CountRows function:

CountRows( Table )

Where,

Table = It is required. Specify the table that you needs to be count all the records within it.

PowerApps countrows filter

In this example, We will see how to work with PowerApps CountRows() function including the Filter function.

  • The below screenshot represents a SharePoint list named Project Details. This list has these many below columns:
  1. Title (By default it is present in the SharePoint list)
  2. Employee First Name (Single line of text)
  3. Employee Last Name (Single line of text)
  4. Employee Job (Choice column)
  5. Client (Choice column)
PowerApps countrows filter
PowerApps countrows filter

PowerApps countrows filter with SharePoint Choice Column

  • Here we will see how to work with the PowerApps count rows filter including SharePoint Choice Column. In the above screenshot, you can see there is a Choice column named Client that has some choice values.
  • Now I would like to count the total number of specific choice-value using the PowerApps CountRows function.
  • To do so, Insert a Label control and apply this below formula on its Text property as:
Text = "Total Number of Filtered Items:" & CountRows(
    Filter(
        'Project Details',
        Client.Value = "TSInfoTechnologies"
    )
)

Where,

  1. “Total Number of Filtered Items:” = This is the text that will display in the label control
  2. ‘Project Details’ = SharePoint List Name
  3. Client.Value = SharePoint Choice column and you need to specify the choice column with the value function
  4. “TSInfoTechnologies” = Specify one choice-value that you want to count
  • Save and Publish the app. Then reopen the app again. You can see the total number of choice values in the label control as shown below.
PowerApps countrows filter items
PowerApps countrows filter example

You may also like, Power Apps Len Function.

PowerApps countrows filter with SharePoint Single Line Text Column

  • Here we will see how to work with the PowerApps count rows filter including SharePoint Single line of text Column. In the above screenshot, you can see there is a Single line column named Employee First Name.
  • Now I would like to count the total number of specific filter items (with a single line column) using the PowerApps CountRows function.
  • To do so, Insert a Label control and apply this below formula on its Text property as:
Text = "Total Number of Filtered Items:" & CountRows(
    Filter(
        'Project Details',
        'Employee First Name' = "Preeti"
    )
)

Refer to the below screenshot.

PowerApps countrows filter item
PowerApps countrows filter with SharePoint
  • Save and Publish the app. Then reopen the app again. You can see the total number of specified values in the label control as in the below screenshot.

PowerApps countrows delegation sharepoint

  • Suppose in your data source, there is a total of 5000 items or records. Here, I want to display all the items (from the Data source) on the PowerApps screen.
  • But there is a limitation in the PowerApps app where it always returns only 500 items (from the data source). This is known as PowerApps Delegation.
  • When you will create a PowerApps application, most of the time you can see there will be a warning sign on the formula, if the function is not delegable. The warning message states that: “Delegation warning: The “filter” part of this formula might not work correctly on large data sets.”
  • Always remember, 500 is the PowerApps Default limit. We can extend this limitation from 500 to 2000 by using the following instructions:
    • Open your PowerApps app
    • Go to the File tab and then Settings
    • Select on Advanced Settings
    • Set the value to 2000 in the Data row limit for non-delegable queries
PowerApps countrows delegation sharepoint
PowerApps countrows delegation sharepoint
  • In some cases, the 2000 record limit can satisfy the requirement. But most of the cases, also may not satisfy because maybe the data source has more than 2000 items (as in my data source it has 5000 records).
  • So in this case, We will do another thing i.e. PowerApps Collection.
  • If you will create a collection, then there will be no delegation limit and one collection can hold at most 10K items or records.
  • At first, you need to save the data for collection. Let’s take an example. Set the below formula on the OnStart property of your app:
OnStart = ClearCollect(collectionname,SharePointlistname)
  • Next, Use this collection to your specific requirement as like:
CountRows(colletionname)

PowerApps countrows sharepoint list

In this example, We will see how we will work PowerApps countrows function with a SharePoint list.

  • The below screenshot represents a SharePoint List named Travel Details. This list has these below columns:
  1. Traveller (By default it is Title column)
  2. Source (Choice column)
  3. Travel Start Date (Date column)
  • Here I want to count total number of Travellers that belongs to Bangalore only. To do so, follow these below things.
PowerApps countrows in a sharepoint list
PowerApps countrows sharepoint list
  • On the PowerApps screen, I have a gallery control with the specific SharePoint List Data source (Travel Details). Here, you can see there is a total three number of travellers that belong to Bangalore only.
PowerApps countrows sharepoint list
PowerApps countrows sharepoint list
  • To count the values, Insert a Label control and apply this below formula on its Text property as:
Text = "Total count of Travellers that belongs to Bangalore: " & CountIf(
    'Travel Details',
    Source.Value = "Bangalore"
)

Where,

  1. ‘Travel Details’ = SharePoint List Name
  2. Source = SharePoint Choice column name

Refer to the below screenshot.

PowerApps countrows in sharepoint list
PowerApps countrows sharepoint list example
  • Once you will save and preview the app, then you can see the value will be 3 that will display in the label control as shown in the above screenshot.

You may also like, How to build multilingual app in PowerApps.

PowerApps countrows gallery or PowerApps count rows in a gallery

Here we will discuss how we can work with the PowerApps CountRows function in Gallery control.

  • On the PowerApps screen, I have a gallery control (Blank Vertical) with these below items as:
Items = ["One","Two","Three"]
PowerApps countrows gallery
PowerApps countrows gallery
  • Now I would like to count the total number of records that are present in the gallery control. Also, I want to count the total number of records (each individual value) that are selected by the user.
  • To count the total number of items from the gallery, you can apply this below formula on Label’s Text property as:
Text = "Total Items in the Gallery: " & CountRows( Gallery1.AllItems)

Where,

  1. “Total Items in the Gallery: “ = This is the text that I want to display in the Label control
  2. Gallery1 = Gallery control name
  • Save and Preview the app. Then you can see there are total four number of records present in the gallery control as like the below screenshot.
PowerApps countrows in gallery
PowerApps count rows in a gallery
  • Similarly, To count the total items where the radio value is One, apply this below formula on Label’s Text property as:
Text = "Total Items where value is One: " & CountRows(Filter( Gallery1.AllItems, Radio1.Selected.Value = "One" ) )

Where,

Radio1 = Radio control name

  • Once you will save and preview the app, you can see there are two records where the value is One.
PowerApps countrows in a gallery
PowerApps count rows in a gallery
  • To count the total items where the radio value is Two, apply this below formula on Label’s Text property as:
Text = "Total Items where value is Two: " & CountRows(Filter( Gallery1.AllItems, Radio1.Selected.Value = "Two" ) )
  • Once you will save and preview the app, you can see there are total three records where the value is Two.
PowerApps count rows in a gallery
PowerApps count rows in a gallery example
  • To count the total items where the radio value is Three, apply this below formula on Label’s Text property as:
Text = "Total Items where value is Three: " & CountRows(Filter( Gallery1.AllItems, Radio1.Selected.Value = "Three" ) )
  • Once you will save and preview the app, you can see there is only one record where the value is Three.
PowerApps count rows in the gallery
PowerApps count rows in a gallery

This is how to count rows on a PowerApps gallery control.

You may like, PowerApps Value Function.

PowerApps countrows datatable

  • In the below screenshot, you can see there is a PowerApps Data table that holds the SharePoint list data source. It has a total five number of records.
  • Now I would like to count the total number of rows that are present inside that specific Data table. That’s why I applied this below formula on Label’s Text property as:
Text = CountRows(DataTable1)

Where,

DataTable1 = Data table name

  • But the problem is, When I applied this formula, it gives me an error as: “Invalid argument type (Control). Expecting a Table value instead. The function ‘CountRows’ has some invalid arguments.” Refer to the below screenshot.
PowerApps countrows datatable
PowerApps countrows datatable
  • The error I am getting because of passing the data table name to the CountRows function does not exist.
  • The solution to this problem is, you need to provide the data source name rather than the data table name. You can find this by viewing the properties of your data table, and going to the Data section.
  • To do so, I applied this below formula on Label’s Text property as:
Text = CountRows(Classes)

Where,

Classes = SharePoint list name

PowerApps count rows in datatable
PowerApps countrows datatable example
  • Once you will save and publish the app, the label will display the total number of items that are having the specified data source.

This is how we can use the PowerApps countrows() function to count rows in a data table.

Check out, How to Create CSV in SharePoint using PowerApps and Power Automate.

PowerApps countrows collection

Here we will see how to work PowerApps Collection using the Countrows function. Lets take a simple scenario.

  • There is a PowerApps Collection named MyListCollection where the items are retrieved from the SharePoint list data source. There are a total five number of records in the PowerApps Collection.
  • Here I would like to count the total number of records that are present in the PowerApps Collection (MyListCollection) and that will display in the Label control.
PowerApps countrows collection
PowerApps countrows collection
  • To do so, apply this below formula on Label’s Text property as:
Text = "Total Number of Items in Collection: " & CountRows(MyListCollection)

Where,

  1. “Total Number of Items in Collection: “ = This is the text that will display in the label control
  2. MyListCollection = Specify the PowerApps collection name
  • Once you will save and preview the app, you can see the total number of records in the label control as in the below screenshot.
PowerApps countrows collections
PowerApps countrows collection

This is how to count rows in a PowerApps collection using countrows() function.

Also, you may like these below PowerApps Tutorials as:

In this PowerApps Tutorial, We discussed what is PowerApps CountRows function, What is its syntax. Also, By taking some simple scenarios, We saw how a user can use it in the PowerApps.

Also, We discussed about these below topics that are related to PowerApps CountRows function as:

  • PowerApps CountRows function
  • PowerApps CountRows function Syntax
  • PowerApps countrows filter
  • PowerApps countrows delegation sharepoint
  • PowerApps countrows sharepoint list
  • PowerApps countrows alternative
  • PowerApps countrows gallery or PowerApps count rows in gallery
  • PowerApps countrows datatable
  • PowerApps countrows collection

>