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 / Optimize a Gallery Ful...
Power Apps
Answered

Optimize a Gallery Full of LookUps

(0) ShareShare
ReportReport
Posted on by 32

Hi

I have created an app to display a roster, by 'Location', which allows a user to click on a 'Position' and make updates (add new employee to a 'Position', remove an employee to a 'Position', and update a current employee at a 'Position'). I am using a SQL table (roughly 1,000 records) connection to record updates. The app works but it is extremely slow on start and to load after a user makes any updates. 

 

I am using a Gallery, which essentially just looks like a grid that looks like this:
Location | Manager | Co-Manager 1 | Co-Manager 2 | Developer | ...

The SQL table supporting this can have multiple records for the same 'Position'/'Location', and I am looking for the most recent "Approved" record. For example, if the table includes 3 records for the Manager position in New York City, it would look like:
Location | Position | Employee_Name | Action | Status | Created_Date

1) 'New York City','Manager','Dave','Create','Approved','7/23/23'

2) 'New York City','Manager','Dave','Delete','Approved','7/24/23'

3) 'New York City','Manager','Steven','Create','Approved','7/25/23'

 

So, in my gallery for the Manager Position in New York City I would want to display 'Steven' since it is the most recent "Approved" record.

I used this formula to get the list of unique 'Locations' from my SQL table:

Sort(AddColumns(GroupBy(Sort(Filter(SQL_Table,Division="D2D"),Created_Date,SortOrder.Descending),"Location_ID","LocationID"),"Unique_Location",First(Location_ID).Location),Unique_Location,SortOrder.Ascending)

Then, I used this formula to get the most recent employee at each 'Position' for each 'Location' (blank if most recent is 'Action' = "Deleted"):

If(LookUp(SortByColumns(SQL_Table,"Created_Date",SortOrder.Descending),Location_ID = ThisItem.Location_ID && Position = "Manager" && Status="Approved",Action)="Delete","",LookUp(SortByColumns(SQL_Table,"Created_Date",SortOrder.Descending),Location_ID = ThisItem.Location_ID && Position = "Manager" && Status="Approved",Employee_Name))

This formula is repeated 12 times (once for each 'Position' at a 'Location'), for every row/record in the Gallery. There are about 150 unique locations so I'm assuming this is a very inefficient way to handle this.

 

Is there a better formula I could be using on these employee LookUps? Is there a way to load everything in once and then only run those LookUps again if that specific 'Position'/'Location' gets an update? Could I maybe use Collections to collect this "grid" and then just reference that Collection? Looking for any idea that can help this run significantly quicker.

 

Thanks

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Hi @dk2311 ,

    I might be missing something here, but are you trying to do this

    AddColumns(
     GroupBy(
     Sort(
     Filter(
     SQL_Table,
     Division = "D2D" && Action <> "Delete" && Position = "Manager" && Status = "Approved",
     ),
     Created_Date,
     SortOrder.Descending
     ),
     "Location_ID",
     "Data"
     ),
     "EmployeeName",
     First(Data).Employee_Name
    )

     

    Please click Accept as solution 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 Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • dk2311 Profile Picture
    32 on at

    Thanks for the response Warren. This formula is nearly identical to the 'Locations' formula I mentioned above, however it is specific to Employee. Since these Employees are inside of the gallery, I needed to make 2 modifications for it to work; 1) add 1 more criteria to the Filter portion of the formula, Location_ID = ThisItem.Location_ID, and 2) wrap the formula you suggested in a First().EmployeeName (since I need a specific field value). 

    The formula would now read: 

    First(
    AddColumns(
     GroupBy(
     Sort(
     Filter(
     SQL_Table,
     Division = "D2D" && Action <> "Delete" && Position = "Manager" && Status = "Approved" && Location_ID = ThisItem.Location_ID,
     ),
     Created_Date,
     SortOrder.Descending
     ),
     "Location_ID",
     "Data"
     ),
     "EmployeeName",
     First(Data).Employee_Name
    )
    ).EmployeeName

     

    However, my issue persists. This solution actually seems to be running slower than the solution I had already. Any changes made using this app require the entire app to "reload" again which takes up to 5 minutes per change.

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    @dk2311 ,

    I am not an SQL user (SharePoint) , but I suspect the speed issue lies elsewhere as that is not a complex formula.

  • Verified answer
    dk2311 Profile Picture
    32 on at

    I ended up finding a solution that works much, much faster. Instead of using various LookUp functions in the gallery itself I just created a Collection that ran all the functions On Start and stored the table. Then the gallery just references that Collection. I set up multiple ClearCollect's throughout the app to collect again once a change has been submitted, so the app only updates when it truly needs to. This is preventing it from constantly running a bunch of LookUps and has resulted in a much smoother user experience.

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 85

#2
WarrenBelz Profile Picture

WarrenBelz 76 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard