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

Community site session details

Session Id :
Power Apps - Building 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:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    152,816 Most Valuable Professional on at
    Help with ClearCollect() and Filter()
    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
    Help with ClearCollect() and Filter()
     
    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,990 Super User 2025 Season 2 on at
    Help with ClearCollect() and Filter()
    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
    152,816 Most Valuable Professional on at
    Help with ClearCollect() and Filter()
    Please have a look at my post at the bottom- I have tested it and it works. 
  • WarrenBelz Profile Picture
    152,816 Most Valuable Professional on at
    Help with ClearCollect() and Filter()
    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

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 803 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 308 Super User 2025 Season 2

#3
SebS Profile Picture

SebS 231 Moderator

Last 30 days Overall leaderboard