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 / Iterate through items ...
Power Apps
Answered

Iterate through items in a powerapps gallery

(0) ShareShare
ReportReport
Posted on by

I have a gallery (gallery1) that stores budget figures for different line items. Then I have another gallery (gallery2) where a user can select a line item from a list that is basically a lookup column from sharepoint based on the line items from gallery1.

When an amount is requested for approval, it goes to gallery2 where the approver selects the line item that corresponds to the description that comes with the amount requested. When the approver clicks "approve", the OnSelect of the icon is set to check the line item selected by the approver in gallery2, against the list of line items in gallery1, where the 2 items match, the amount requested is subtracted from the current balance of the selected line item.

I put the following in the OnSelect property of the gallery2 icon but it doesn't work as expected...

 

If(
(gallery1.Selected.LineItem = ThisItem.LineItem.Value) = true && !IsBlank(gal_NewBudget_3.Selected.CurrentBalance) && (gallery1.Selected.CurrentBalance - ThisItem.AmountRequested) > 0,
UpdateContext({varSub: gallery1.Selected.CurrentBalance - ThisItem.AmountRequested}),
Patch (
Vouchers, ThisItem,
{ExceededValue: "yes"}
)
);

 

However, this only compares the gallery2 line item with the first item in gallery1 and does not continue on to check the other items in the gallery. My expectation was for it to go through and compare all the items in gallery1 with the selected gallery2 item and perform the subtraction where the two line items match.

I've tried to use the ForAll function, but I don't exactly know how to go about it or if that's even what I should be using.

I would really appreciate any help/guidance on this. Thanks.

 

Gallery2

AdaEloka_0-1694605722151.png

 

Gallery1

AdaEloka_1-1694605809393.png

 

 

Categories:
I have the same question (0)
  • Chris-D Profile Picture
    1,246 on at

    Hi @AdaEloka, this is only working on the gallery selected row because you're using gallery1.Selected as the comparison. 

     

    You're correct to use ForAll(), I'm not exactly sure what's going on with the rest of your code but here's how to use ForAll() to loop a gallery:

    ForAll( 
     // The AllItems property contains the gallery rows
     MyGallery.AllItems As GalleryItem,
    
     If( 
     // Here, GalleryItem refers to the gallery row
     GalleryItem.Something = SomethingElse,
    
     true,
     false
     )
    )
    
  • Verified answer
    AdaEloka Profile Picture
    on at

    Hi Chris,

     

    Thanks for your answer. 

     

    I was able to solve this by checking that the record existed in the gallery and then filtering the record I needed into a collection that I could then work with. I wasn't really sure how to progress with ForAll. What I have now looks like this:

     

    If(
    (ThisItem.LineItem.Value exactin gal_NewBudget_3.AllItems.LineItem) = true,
    ClearCollect(
    colSubtract,
    Filter(
    colBudgetFilter,
    LineItem = ThisItem.LineItem.Value
    )
    )
    );
    If(
    !IsBlank(First(colSubtract).CurrentBalance) && (First(colSubtract).CurrentBalance - ThisItem.AmountRequested) > 0,
    UpdateContext({varSub: First(colSubtract).CurrentBalance - ThisItem.AmountRequested}),
    Patch (
    Vouchers,
    ThisItem,
    {ExceededValue: "yes"}
    )
    );

  • Chris-D Profile Picture
    1,246 on at

    No problem, glad it's working. 

  • Naqib Profile Picture
    7 on at

    I have the same issue, I used on only if condition, it worked for the first record, but for all records, I need to use "ForAll" but then things stopped working. 

    This is how my codes look like:

    ForAll(
        MainPage.AllItems,
        If(
            IsBlank(Label1.Text),
            Notify(
                "Some reports are incomplete, please complete them and continue!",
                NotificationType.Error
            ),
            Set(
                varshowpopup,
                true
            )
        )
    )
  • AdaEloka Profile Picture
    on at

    Hi @Naqib ,

    How about something like this? It's just an idea...

    UpdateContext(
     {
     varRecord: LookUp(
     YourDataSource,
     YourColumn = Blank()
     ).ID
     }
    );
    
    ForAll(
     YourGallery.AllItems, //assuming that your gallery contains all the items in your data source
     If(
     IsBlank(varRecord),
     Notify(
     "Some reports are incomplete, please complete them and continue!",
     NotificationType.Error
     ),
     Set(
     varshowpopup,
     true
     )
     )
    )

     

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 765 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 272

Last 30 days Overall leaderboard