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 / ForEach item in a gallery
Power Apps
Answered

ForEach item in a gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Is there a way to iterate through each item in a gallery and set one of it's rows values?  I have a list of people where due to business rules, only ONE can be activated at a time (I have a column in the SQL table for active).  In the list, I have a red X (inactive) and a green check mark (for active).  All the user needs to do is to click on the icon and it changes it in the sql database (to either active or inactive) and also displays the correct icon.  This all works, but now I need to iterate through the list and what I want it to do is to set that Active flag to Inactive on all that were not selected.

 

Is there a 'ForEach' routine or what would be the easiest to accomplish this?  And I am sure I would use a Patch statement to update the SQL table.

 

Brad

Categories:
I have the same question (0)
  • dinusc Profile Picture
    Microsoft Employee on at

    Hello Btrad,

     

    I would suggest setting the "Active" flagg according to the ThisItem.IsSelected flag in the gallery.

  • Verified answer
    Brian Dang Profile Picture
    3,976 on at

    Hi @Anonymous,

    The ForAll() function lets you loop actions. But for your use case you may have some easier options available like UpdateIf.

     

    I would set the OnSelect actions of the X and checkmark to set a variable to what's selected in the gallery:

     

    Set(selectedItem,ThisItem)

    In the same button, have these actions:

     

    If you click the check mark:
    
    UpdateIf(dbo.datasource,1=1,
     {
     flag: If(Id=selectedItem.Id,"Active","Inactive")
     }
    )

    This means, "Update all records in the datasource (1=1 returns true for all records) so that if the Id of the record matches the selected record, make it active, else make it inactive."

     

    If you hit delegation issues with UpdateIf--like you have more than 500 people, you can use ForAll() with Patch()-- let me know if that is the case and I can write up a sample. But there might be a few samples on this forum if you search for ForAll and Patch.

     

    Brian

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Brian,

     

    Thank you!  There are always functions I dont know about and learn every day.  This works just fine the way it is written.  There will never be 500 people in the table.  Maybe 20 at most.  Is there a list of Power Apps functions someplace as an easy reference?  And also now if I could get a spinner that says "working".  I know we have the little dots on top the screen.  I wonder if I can use Notify for an informational message.

     

    Brad

  • Brian Dang Profile Picture
    3,976 on at

    Hi @Anonymous,

    I have a series started on this particular need.

     

    Here's part 2 that goes into the importance of the Formula Reference:

    https://powerapps.microsoft.com/en-us/blog/learning-with-mr-dang-transferring-knowledge-1/

     

    Some direct links to the references themselves:

    Formula Reference

    Formula Checklist - Excel

    Formula Checklist - OneNote

     

    If you have dots running on the screen, it's likely you used SubmitForm, Patch, or Collect to call data. In that case, you may want to run Notify() ahead of those actions.

     

    I recently responded to a question about the "marching ants"--you might find the answer in the recent list of topics 🙂

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 762

#2
11manish Profile Picture

11manish 640

#3
Valantis Profile Picture

Valantis 548

Last 30 days Overall leaderboard