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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Adding Columns to a Co...
Power Apps
Suggested Answer

Adding Columns to a Collection

(1) ShareShare
ReportReport
Posted on by 439
Hi all,
 
I am creating a collection, collectionA, to consist of the records in a Gallery when a Checkbox is Checked by the following expression:
 
ForAll(
    'Options-gal'.AllItems,
    If(
        'Options-gal-checkbox'.Value = true,
        Collect(
            colOptionsSelected,
            ThisRecord
        );
 
I want to add two columns to this collection, alongside the record that is collected. The columns can be named ColumnA and ColumnB for this example. The purpose is that these columns will have a value of 0 at this time, and they will be patched with another value later in the App.
 
In other words, let's say there were three items in the gallery. Only two of them, records 1 and 2, had the checkbox checked. collectionA should consist of two records. The records should have two extra columns, ColumnA and ColumnB, both with a value of 0.
 
I have tried 'AddColumns' but cannot get it to work, either there's an error in the PowerFX, or, no error but when I examine the Collection it has not added the Columns.
 
I remember having to do this before in an App a couple of years ago and it was very frustrating then; I can't recall how I fixed it and to avoid wasting more time on this, could anyone assist with the relevant solution?
 
Many thanks!
Categories:
I have the same question (0)
  • pp365 Profile Picture
    439 on at
    Hi everyone, just re-raising this, can anyone assist? Many thanks!
  • mstavra Profile Picture
    247 on at
    Hey, have you tried this?

     Collect(
    colOptionsSelected,
         AddColumns(
              ThisRecord,
              "ColumnA", 0,
              "ColumnB", 0
         )
    )
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at
    hey 
     
    Can u please try this:
     
    ForAll(
        'Options-gal'.AllItems,
        If(
            'Options-gal-checkbox'.Value = true,
            Collect(
                colOptionsSelected,
                {
                    OriginalRecord: ThisRecord,
                    ColumnA: 0,
                    ColumnB: 0
                }
            )
        )
    );
    
    If the Post help you solve your issue, please mark it as verified answer and give it a like so we can help other in the community with similar issues 

    Greetings
     
  • pp365 Profile Picture
    439 on at
    Hi @mmbr1606
     
    (Sorry, I can't see in this new interface why the @ mention doesn't seem to work anymore, nor how to reply to a specific post!).
     
    Thank you very much for your suggestion. We're part of the way there: the two columns A & B are being created successfully with the value of 0 in each, also, the correct number of records (2) are in the collection (as shown in the screenshot below).
     
    The part that's not quite right is 'OriginalRecord' has been added as a column to the collection, which contains 'ThisRecord' as a Record. I understand that's correct in terms of the syntax provided, but what I want is, automatically, all of the columns of 'ThisRecord' to be created in the Collection automatically, with the two columns A & B to be added to this list.
     
    Taking the below screenshot as an example. ThisRecord will include a value for Author, and for 'CommentsToUserForOptionsDets'. I want those values in line on a single record with the ColumnA value and the ColumnB value, not contained as a record within a record.
     
    Is this possible to achieve? Many thanks!
     
     
     
  • Suggested answer
    CT-25070802-0 Profile Picture
    43 on at
    Hello, 
     
    I think you can't use "'Options-gal-checkbox'.Value = true," in the ForAll because
    "Options-gal-checkbox" is a controller and not an field of the collection.
     
    Can you try to :
    - add a column named "Selected"
    - use the OnCheck event of the checkbox to patch the collection 
    Patch(
       CollectionA;
       LookUp(CollectionA;ID=ThisItem.ID);
       {
          Selected=true
       }
    )
     
    If you want a collection with only selected items :
    Clearcollect(
       NewCollection;
       AddColumns(
            Filter(
               CollectionA;
               Selected=true
             );
            "ColumnA";0;
            "ColumnB";0
        )
    )
     
    Let me know if it works.
     
     
     

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

Forum hierarchy changes are complete!

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard