web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help with ClearCollect...
Power Apps
Answered

Help with ClearCollect() and Filter()

(0) ShareShare
ReportReport
Posted on by
Hello, I have a SharePoint list that I am using as a Data Source in my Power App. It has a text column in it called "Team".
I am trying to create a collection to then use in a pie chart using the following code:
 
ClearCollect(
    TeamCollection,
    ForAll(
        ["Safety & Security", "Control & Software", "Engineering Management", "Electrical & Electronics", "Systems"],  // List of team names
        {
            Team: ThisRecord,  // Current team name
            Count: CountRows(
                Filter(
                    'Form Answers',
                    Team = ThisRecord  // Compare the text column's value
                )
            )
        }
    )
);
I get the error: Incompatible types for comparison. These types can't be compared: Text, Record.
 
The error shows on the "=" on line 10.

I have tried adding ".Value" onto the end of ThisRecord which gives me a name not found error.
 
Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,967 Most Valuable Professional on at
    Try this
    ClearCollect(
       TeamCollection,
       ForAll(
          ["Safety & Security", "Control & Software", "Engineering Management", "Electrical & Electronics", "Systems"],
          {
             Team: Value,
             Count: 
             CountRows(
                Filter(
                   'Form Answers',
                   Team = Value
                )
             )
          }
       )
    );
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee

  • Suggested answer
    Rayon Robert Profile Picture
    20 on at
     
    I tried re-creating the your inputs for the required output.
    Below is the snip of the 'Form Answers' where I have 'Control Software' value containing 2 entries (for instance).
     
    In order to collect per your requirement, I have updated the below code where the Value from your 'Form Answers' are used to calculate the count.
     
    ClearCollect(
        TeamCollection,
        ForAll(
            ["Safety & Security", "Control & Software", "Engineering Management", "Electrical & Electronics", "Systems"], // List of team names
            {
                Team: Value, // Current team name
                Count: CountRows(
                    Filter(
                        colFormAnswers,
                        Team = Value // Compare the "Team" column's value in the data source
                    )
                )
            }
        )
    );
     

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
     
  • Suggested answer
    SaiRT14 Profile Picture
    1,992 Super User 2025 Season 1 on at
    Error because ThisRecord in the ForAll loop is a record, not text.
     
    here is the corrected code, pls try:
    ClearCollect(
        TeamCollection,
        ForAll(
            ["Safety & Security", "Control & Software", "Engineering Management", "Electrical & Electronics", "Systems"],  // List of team names
            {
                Team: ThisRecord,  // Current team name
                Count: CountRows(
                    Filter(
                        'Form Answers',
                        Team = ThisRecord.Value  // Use ThisRecord.Value to get the actual text value
                    )
                )
            }
        )
    );
     
  • WarrenBelz Profile Picture
    156,967 Most Valuable Professional on at
    Please have a look at my post at the bottom- I have tested it and it works. 
  • WarrenBelz Profile Picture
    156,967 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps   

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard