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 / Looping commands throu...
Power Apps
Answered

Looping commands through all items in a gallery

(0) ShareShare
ReportReport
Posted on by 6

I am trying to execute the following code for all items in a gallery. This code is functional, but it only completes the commands for one item in the gallery.

 

I seem to be struggling with figuring out how to loop through all items in a gallery and more specifically the syntax required to reference the Participant_ID for each loop.

 

It seems important to note that the Sum(Filter function is using the Participant_ID from the gallery item to look up the sum of the Amount column where that same Participant_ID exists in the rows of an entirely separate table than what the Gallery is depicting.  

 

I have been at this for a while so any help would be appreciated.

 

 

If(
 Sum(
 Filter(
 Profile_Bank,
 Participant_ID = ThisItem.Participant_ID
 ),
 Amount
 ) > 9,
 UpdateIf(
 'Thumbs Up User Data',
 Participant_ID = ThisItem.Participant_ID,
 {
 Money_Overage: Sum(
 Filter(
 Profile_Bank,
 Participant_ID = ThisItem.Participant_ID
 ),
 Amount
 )
 };
 );
 Patch(
 'Thumbs Up Bank',
 Defaults('Thumbs Up Bank'),
 {
 Title: "Annual Adjustment",
 Participant_ID: ThisItem.Participant_ID,
 Customer: LookUp(
 'Thumbs Up User Data',
 Participant_ID = ThisItem.Participant_ID,
 fName
 ),
 Customer_Email: LookUp(
 'Thumbs Up User Data',
 Participant_ID = varParticipantID,
 Email_Column
 ),
 Amount: -1 * Sum(
 Filter(
 Profile_Bank,
 Participant_ID = ThisItem.Participant_ID
 ),
 Amount
 ),
 Date_Created: Text(
 Now(),
 LongDateTime
 )
 }
 );
 ClearCollect(
 ThumbsUpUserDataCache,
 'Thumbs Up User Data'
 );
 ClearCollect(
 Profile_Bank,
 'Thumbs Up Bank'
 );
 ClearCollect(
 ThumbsUpUserDataCache,
 'Thumbs Up User Data'
 );
 ClearCollect(
 Profile_Bank,
 'Thumbs Up Bank'
 );
 
)

 

 

Categories:
I have the same question (0)
  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @Guff09 

     

    Edited: You need to loop through the gallery. To avoid name conflict we need to have a collection.

     

     

    ClearCollect(
     TempCollection,
     RenameColumns(
     BrowseGallery.AllItems,
     "Participant_ID",
     "NewParticipant_ID"
     )
    );
    
    ForAll(
    TempCollection,
    If(
     Sum(
     Filter(
     Profile_Bank,
     Participant_ID = NewParticipant_ID
     ),
     Amount
     ) > 9,
     UpdateIf(
     'Thumbs Up User Data',
     Participant_ID = NewParticipant_ID,
     {
     Money_Overage: Sum(
     Filter(
     Profile_Bank,
     Participant_ID = NewParticipant_ID
     ),
     Amount
     )
     };
     );
     Patch(
     'Thumbs Up Bank',
     Defaults('Thumbs Up Bank'),
     {
     Title: "Annual Adjustment",
     Participant_ID: NewParticipant_ID,
     Customer: LookUp(
     'Thumbs Up User Data',
     Participant_ID = NewParticipant_ID,
     fName
     ),
     Customer_Email: LookUp(
     'Thumbs Up User Data',
     Participant_ID = varParticipantID,
     Email_Column
     ),
     Amount: -1 * Sum(
     Filter(
     Profile_Bank,
     Participant_ID = NewParticipant_ID
     ),
     Amount
     ),
     Date_Created: Text(
     Now(),
     LongDateTime
     )
     }
     );
     ClearCollect(
     ThumbsUpUserDataCache,
     'Thumbs Up User Data'
     );
     ClearCollect(
     Profile_Bank,
     'Thumbs Up Bank'
     );
     ClearCollect(
     ThumbsUpUserDataCache,
     'Thumbs Up User Data'
     );
     ClearCollect(
     Profile_Bank,
     'Thumbs Up Bank'
     );
     
    )
    )

     

     

  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @Guff09 

     

    As I mentioned,

     

    • Need a temp collection to avoid name conflict. In this case, the system will not identify Partcipant_ID
    • Reference the new ID in all the places wherever ThisItem used
  • Guff09 Profile Picture
    6 on at

    Thank you very much. This worked perfectly.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard