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 / Add Sort Button to Gal...
Power Apps
Answered

Add Sort Button to Gallery

(1) ShareShare
ReportReport
Posted on by 22

Hi guys,

 

I have a Gallery showing data from 2 different SP lists.

 

List 1 - Opportunities 

List 2 - Companies

 

My Gallery is currently sorted by the ID column by default, which I want to keep. But I'd like to have the option to sort by Company Name as well by adding a Sort Button.

 

Here's the code for my Gallery:

 

SortByColumns(
Filter(Opportunities,
IsBlank(ComboBox2.SelectedItems) || IsEmpty(ComboBox2.SelectedItems) || Status in ComboBox2.SelectedItems,
IsBlank(ComboBox2_1.SelectedItems) || IsEmpty(ComboBox2_1.SelectedItems) || LookUp(Companies, ID = CompanyID, Country) in ComboBox2_1.SelectedItems,
CompanyID in Search(Companies, TextInputSearch_2.Text,"Name").ID),
"ID", Descending)

 

The column I want to sort by: LookUp(Companies, ID = ThisItem.CompanyID, Name).

 

It seems simple and I've tried so many different ways but I don't know what I'm doing wrong.

 

Any help would be appreciated. Thanks

Categories:
  • TheRobRush Profile Picture
    11,128 Moderator on at

    Make a sort button icon at top of each column, like a down or up arrow etc, have that set a variable, then reference that variable in your items when you do your filter and sort

  • Verified answer
    v-albai-msft Profile Picture
    Microsoft Employee on at

    Hi @raffbrito ,

    This is because your CompanyName(Name) column inside the gallery is populated from another list, you cannot directly sort by this column value.

    For sorting by this column, you need to add another column for your Opportunities list to keep the Company Name value.

    So try below solution.

    1. Set OnStart property of your app to below:

     

    ClearCollect(Col_Opportunities,AddColumns(Opportunities,"Company_Name", LookUp(Companies, CompanyID=ID, Name)))

     

    2. For your gallery, try this code:

     

    SortByColumns(

    Filter(Col_Opportunities,

    IsBlank(ComboBox2.SelectedItems) || IsEmpty(ComboBox2.SelectedItems) || Status in ComboBox2.SelectedItems,

    IsBlank(ComboBox2_1.SelectedItems) || IsEmpty(ComboBox2_1.SelectedItems) || LookUp(Companies, ID = CompanyID, Country) in ComboBox2_1.SelectedItems,

    CompanyID in Search(Companies, TextInputSearch_2.Text,"Name").ID),

    "ID", Descending)

     

    3. For the new sort button, you should try this formula:

     

    SortByColumns(Col_Opportunities," Company_Name", Ascending)

     

    Best regards,

    Allen

  • v-albai-msft Profile Picture
    Microsoft Employee on at

    Hi @raffbrito ,

    How are things going?

    Is any reply helpful to you? 

    Best regards,

    Allen

  • raffbrito Profile Picture
    22 on at

    Thanks!!

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 130

Last 30 days Overall leaderboard