CountRows

How to Use the Power Fx CountRows  Function in Power Apps

One of the most useful functions in Power Fx is the CountRows function, which lets you count the number of rows in a table or collection. In this article, we’ll take a look at how to use the CountRows function in Power Apps.

What is the CountRows function?

The CountRows function is a built-in function in Power Fx that lets you count the number of rows in a table or collection. It takes a single argument, which is the table or collection that you want to count. The function returns a number that represents the total number of rows in the specified table or collection.

For example, if you have a table called “Customers” that contains 100 rows, you can use the CountRows function to count the number of rows in the table like this:


CountRows(Customers)


This will return the value “100”, which is the total number of rows in the “Customers” table.

Using the CountRows function in Power Apps

The CountRows function is especially useful in Power Apps, where you may need to count the number of records in a collection or table to display the information to users. Here’s an example of how to use the CountRows function in Power Apps:

1. Create a new screen in Power Apps.

2. Add a new gallery to the screen by clicking “Insert” and selecting “Gallery”.

3. Select the data source for the gallery. This can be a table or collection.

4. Add a label to the gallery by clicking “Insert” and selecting “Label”.

5. Set the text property of the label to the CountRows function, like this:


CountRows(MyCollection)


6. Save and publish the app.

Now, when users navigate to this screen, they will see a gallery that displays the total number of rows in the specified table or collection.

Using the CountRows function with filters

Another useful feature of the CountRows function is that you can use it with filters to count only specific rows in a table or collection. For example, if you have a collection called “Employees” that contains information about all the employees in your company, you can use the CountRows function to count the number of employees who work in a specific department like this:


CountRows(Filter(Employees, Department = "Sales"))


This will return the total number of employees who work in the “Sales” department.

You can also use the CountRows function with other filter criteria, such as date ranges, employee titles, or any other field in your data source.

The CountRows function is a powerful tool that lets you count the number of rows in a table or collection in Power Apps. It’s a simple yet essential function that can help you display information to users and perform other advanced tasks in your applications. By using the CountRows function with filters, you can even count only specific rows in your data source, making it a versatile function that you’ll use time and time again in your Power Apps projects.

Power Apps Training Courses by G Com Solutions (0800 998 9248)