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 / Sorting a Gallery base...
Power Apps
Answered

Sorting a Gallery based on a LookUp Column

(0) ShareShare
ReportReport
Posted on by 99

I have a gallery that displays a value from a lookup column and would like to be able to sort on that column. I've read a couple of posts that are similar, but I can't seem to wrap my brain around how to apply this to exactly what I'm doing.

 

My gallery header has sort icons next to the columns that users can sort on.

tsparkman_1-1617218790938.png

 

When a sort icon is selected, it sets a variable that indicates which column they are sorting on.

 

My gallery Items property is:

  1. Filtering on the Project Status = In Progress
  2. Sorting based on the variable that was set with  the above icon was clicked
  3. And searching based on text entered in a search box:

 

 

Filter(

SortByColumns(
Search(
CSProjects,
input_Search.Text,
"Title"
),
varSortBy,
If(
varSortOrder,
Ascending,
Descending
)
),
ProjectStatus.Value = "In Progress"
)

 

 

This works fine for the Project Name and Due Date columns. However, the Portfolio column is a lookup to another SharePoint list. 

 

From what I've read, I think I need to somehow use AddColumns but am not sure where to place that in the above code. And I'm not really sure what syntax I need in the AddColumns, something like this (maybe???). Any help or insight is greatly appreciated!

 

 

AddColumns(
 CSPortfolios, //Name of the Lookup List
 "Title" //Name of the column that stores the portfolio name in the CSPortfolios list
 Portfolio.Value //The Porfolio field that is in my Gallery
 )

 

 

 

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,532 Most Valuable Professional on at

    Hi @tsparkman ,

    AddColumns is correct, but like this

    Filter(
     SortByColumns(
     Search(
     AddColumns(
     CSProjects,
     "MySort",
     YourLookupName.Value
     ),
     input_Search.Text,
     "Title"
     ),
     "MySort",
     If(
     varSortOrder,
     Ascending,
     Descending
     )
     ),
     ProjectStatus.Value = "In Progress"
    )

    Note however that the output of AddColumns() is subject to your Delegation limit.

     

    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.

     

  • Verified answer
    tsparkman Profile Picture
    99 on at

    Hi @WarrenBelz  -

     

    YAY...that worked. Thank you SO MUCH!

  • MarcSigrist Profile Picture
    20 on at

    Hi,

     

    Unfortunately the AddColumns()-approach causes delegation issues, if the Datasource is Dataverse.

    I wrote a blog post about this topic with a solution (for Dataverse) that does not cause delegation issues: Power Apps: Sort by Dataverse lookup column, without delegation. (powerfully.ch)

     

    Please have a look. Thank you.

    Marc

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
11manish Profile Picture

11manish 411 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 338

#3
WarrenBelz Profile Picture

WarrenBelz 256 Most Valuable Professional

Last 30 days Overall leaderboard