Count() in Power Apps with Examples

As a Power Apps app developer, you will often be required to use the count() function in Power Apps. So, you should know how to use the Power Apps count() function. In this tutorial, I will explain how to use count() in Power Apps with some real examples.

Many related count functions are available, such as CountA, CountIf, and CountRows. But we will focus only on Count in Power Apps here.

What is the Count Function in Power Apps?

The Count function in Power Apps is specifically used to count the non-blank numeric values in a single-column table. It doesn’t count the total number of records; it counts the number of numeric and non-blank values in that single column.

Syntax:

Count( SingleColumnTable )
  • SingleColumnTable = The function expects the arguments to be a single-column table.
  • The column in the table must contain numeric values (e.g., 1,4,0.8, etc). If the column contains text or blank values, those won’t be counted.

Example: Power Apps single column table [collection] with numeric values.

ClearCollect(colCustomerFeedback, 
    { FeedbackRating: 4},
    { FeedbackRating: 5},
    { FeedbackRating: Blank()},
    { FeedbackRating: 3},
    { FeedbackRating: 7}
);
 Count(colCustomerFeedback) = 4
power apps count function

Now, let me tell you a few points why the Power Apps Count() function is important:

  • Count Numeric Data: Count() quickly counts the number of non-blank numeric entries in a column, which is helpful when working with data that needs to be summarized.
  • Efficiency: The Count() function can reduce the need for manual calculations.

Check out How to Get Current User Details in Power Apps

How to use the Count() Function in Power Apps

Example: Count the records in the Power Apps table with multiple columns.

Here is the collection that contains three columns. Make sure the table includes a number field.

  • Product
  • SaleAmount
  • Sold
ClearCollect(colProductSales, 
    {Product: "Laptop", SaleAmount: 1500, Sold: "Yes"},
    {Product: "Phone", SaleAmount: 800, Sold: "Yes"},
    {Product: "Headphones", SaleAmount: 300, Sold: "Yes"},
    {Product: "Mouse", SaleAmount: Blank(), Sold: "No"},
    {Product: "Keyboard", SaleAmount: 120, Sold: "Yes"},
    {Product: "Printer", SaleAmount: 1500, Sold: "Yes"},
    {Product: "Scanner", SaleAmount: 800, Sold: "Yes"},
    {Product: "Photocopier", SaleAmount: 300, Sold: "Yes"}
);

Get the number of Records:

Count(colProductSales.SaleAmount)

This Count () function returns 7, excluding the record with a Blank() value.

PowerApps count items in table

Let me show you more examples of using the Count() function in Power Apps.

Read Power Apps Modern Form Control

Count with Filter Function in Power Apps

Example: Get the records from Power Apps table based on a condition.

Note:

When a table has multiple columns, this filter condition within the count function won’t work.

Here is the collection with a single number field [FeedbackRating].

ClearCollect(colCustomerFeedback, 
    { FeedbackRating: 4},
    { FeedbackRating: 5},
    { FeedbackRating: Blank()},
    { FeedbackRating: 3},
    { FeedbackRating: Blank()},
    { FeedbackRating: 1},
    { FeedbackRating: 4},
    { FeedbackRating: 3},
    { FeedbackRating: 1},
    { FeedbackRating: 2},
    { FeedbackRating: 1}
);

The Power Apps Count () with the filter function.

 Count(Filter(colCustomerFeedback,FeedbackRating <=3))
PowerApps count rows in table with Filter

The output is the number of records with a feedback rating less than or equal to 3 and non-blank values.

Change Background Colors Based on Power Apps Count

Example: Change the background color based on the count of customer feedback ratings in Power Apps.

If(Count(Filter(colCustomerFeedback,FeedbackRating <=3)) > 5,RGBA(187, 221, 140, 1),RGBA(251, 188, 159, 1))

If the count value exceeds 5, the label will be filled with RGBA(187, 221, 140, 1) color, otherwise with this RGBA(251, 188, 159, 1) color.

Power Apps count rows in gallery with Filter

Calculate Percentages Using Power Apps Count()

Example 1: Calculate percentages of customer feedback ratings( 1 to 5) using Power Apps Count().

In this example, we will see how to calculate the percentage for each feedback rating (from 1 to 5) and display the results in a Power Apps slider control.

Calculate count and percentage operation within one column

1. To get the percentage of each feedback rating, use the code below

"1 = "&Round((Count(Filter(colCustomerFeedback,FeedbackRating =1))/Count(colCustomerFeedback))*100,0) & " %"

Here,

  • Count(Filter(colCustomerFeedback, FeedbackRating =1): It gets the number of records with feedback value of 1.
  • Count(colCustomerFeedback): Returns the total count of records which are not blank.
  • (Count(Filter(colCustomerFeedback,FeedbackRating =1))/Count(colCustomerFeedback))*100: Returns the percentage of feedback value 1 in decimal format.
  • Round(): Removes the decimal values in the percentage.

To calculate the percentage, replace the 1 within the count function with the remaining number, such as 2, 3, 4, and 5.

calculate percentage with power apps count filter

2. Add five slider controls and provide the formulas below in their Default property.

Feedback value 1:   (Count(Filter(colCustomerFeedback,FeedbackRating  =1))/Count(colCustomerFeedback))*100

Feedback value 2: (Count(Filter(colCustomerFeedback,FeedbackRating  =2))/Count(colCustomerFeedback))*100

Feedback value 3: (Count(Filter(colCustomerFeedback,FeedbackRating  =3))/Count(colCustomerFeedback))*100

Feedback value 4: (Count(Filter(colCustomerFeedback,FeedbackRating  =4))/Count(colCustomerFeedback))*100

Feedback value 5: (Count(Filter(colCustomerFeedback,FeedbackRating  =5))/Count(colCustomerFeedback))*100

The above formulas calculate the percentage of the specified feedback value.

progress indicator with power apps count filter

Example 2: Display different feedback messages depending on the percentage.

In this example, we will display different feedback messages based on the percentage for each feedback.

power apps count function examples

1. Create Power Apps local variables to store each feedback rating’s percentages. Provide the below code on the OnVisible property of the current screen.

UpdateContext({
    feedbackCompletionRate1: Round(Count(Filter(colCustomerFeedback, FeedbackRating = 1)) / Count(colCustomerFeedback) * 100, 0),

    feedbackCompletionRate2: Round(Count(Filter(colCustomerFeedback, FeedbackRating = 2)) / Count(colCustomerFeedback) * 100, 0),

    feedbackCompletionRate3: Round(Count(Filter(colCustomerFeedback, FeedbackRating = 3)) / Count(colCustomerFeedback) * 100, 0),

    feedbackCompletionRate4: Round(Count(Filter(colCustomerFeedback, FeedbackRating = 4)) / Count(colCustomerFeedback) * 100, 0),

    feedbackCompletionRate5: Round(Count(Filter(colCustomerFeedback, FeedbackRating = 5)) / Count(colCustomerFeedback) * 100, 0)
});

Here,

  • feedbackCompletionRate1, 2, 3, 4,5 are the variables storing each feedback percentage.
  • Count(Filter(colCustomerFeedback, FeedbackRating = 1)) / Count(colCustomerFeedback) * 100) is calculating the percentage.

2. Now, add labels to display percentages and feedback messages.

If(
    feedbackCompletionRate1 < 20,
    " 1 = " & feedbackCompletionRate1 & "% - Needs Improvement",
    If(
        feedbackCompletionRate1 < 50,
        "1 = " & feedbackCompletionRate1 & "% - Feedback is Fair",
        "1 = " & feedbackCompletionRate1 & "% - Great Feedback"
    )
)

Here,

  • feedbackCompletionRate1 = Variable storing the percentage of feedback value 1.
  • If the percentage is less than 20, it displays a “Needs Improvement” message. Less than 50 means “Feedback is Fair” and greater than 50 means “Great Feedback.”

For the remaining feedback values, replace feedbackCompletionRate1 with the required variables.

powerapps count items in gallery with conditions

Read Show Hide Fields Based On Power Apps Dropdown Selection

Error Handling with IsEmpty in Power Apps

In this example, we will see how to handle situations where the table may be empty. The IsEmpty() function checks if a table is empty, and we handle the exception by displaying a message when no feedback is available, or showing the count of feedback if data exists.

If(
    IsEmpty(colCustomerFeedback) || Count(colCustomerFeedback) = 0,
    "No Feedback Available",
    "Found " & Count(colCustomerFeedback) & " Feedbacks"
)
power apps error handling for count function

Check out Export Data from Data Table to Excel in Power Apps

Power Apps Count with Conditions

In this section, we will see how to use the Power Apps Count function along with conditions. We will apply && and || operators to count records that match specific conditions.

Example 1: Count the number of records in the Power Apps table where the sale amount is between two specified values( 500 and 1200).

Here, I have a collection [colSales] with a single number field named SaleAmount.

ClearCollect(colSales, 
    {SaleAmount: 1500},
    {SaleAmount: 800},
    {SaleAmount: 300},
    {SaleAmount: Blank()},
    {SaleAmount: 1200},
    {SaleAmount: 1500},
    {SaleAmount: 800},
    {SaleAmount: 300},
    {SaleAmount: 1200}
);

Condition:

"Count: "&Count(Filter(colSales,SaleAmount >500 && SaleAmount <= 1200))

It returns the number of records from the table with a SaleAmount greater than 500 and less than or equal to 1200.

power apps count example with logical or condition

Example 2: Count the number of records in the Power Apps table where the sale amount is either 800 or less than or equal to 1200.

"Count: "&Count(Filter(colSales,SaleAmount =800 || SaleAmount <= 1200))
power apps count with logical or condition

So these are some examples of using Power Apps Count function with conditions.

I hope now you understand how to work with count in Power Apps. I have also shown a few real examples of using the Power Apps Count() function. Do let me know if you still have any questions.

Also, you may like:

1 thought on “Count() in Power Apps with Examples”

Leave a Comment

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App