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 / How to add multiple So...
Power Apps
Answered

How to add multiple Sorts on a Gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I was following this video here:

https://www.youtube.com/watch?v=8bNCBe2wzYI

 

I have a gallery, that is pulling from my Engineers table.

 

lardo5150_0-1646169715017.png

 

So my thinking was, as there are two different teams mixed in there.

If I click the button that says EXO, it changes the variable below:

Set(var_engineertype,"Online")

Clicking the other will change it to "On-Prem"

In the items of my gallery, I have this:

Filter(Engineers,EngineerType.Value=var_engineertype)

 

This is working as expected.  It switches the engineers.

I am having trouble figuring out the filtering AND MULTIPLE Sorting.

 

So for my onvisible screen, I ahve this:

Refresh(Engineers);
UpdateContext({var_Eng:Blank()});
UpdateContext({var_TotalCasesSort:Blank()});
UpdateContext({var_TotalCrits:Blank()});
UpdateContext({var_LastAssigned:Blank()});
UpdateContext({var_LastCritAssigned:Blank()});
If(!IsBlank(var_Eng),SortByColumns(Engineers,"EngineerDisplayName",If(var_Eng=true,Ascending, Descending)));
If(!IsBlank(var_TotalCasesSort),SortByColumns(Engineers,"TotalAssigned",If(var_TotalCasesSort=true,Ascending, Descending)));
If(!IsBlank(var_TotalCrits),SortByColumns(Engineers,"CritAssigned",If(var_TotalCrits=true,Ascending, Descending)));
If(!IsBlank(var_LastAssigned),SortByColumns(Engineers,"LastAssigned",If(var_LastAssigned=true,Ascending, Descending)));
If(!IsBlank(var_LastCritAssigned),SortByColumns(Engineers,"LastCritAssigned",If(var_LastCritAssigned=true,Ascending, Descending)));

 

On each of my Sort Icons, I ahve this:

UpdateContext({var_TotalCasesSort:Blank()});
UpdateContext({var_TotalCrits:Blank()});
UpdateContext({var_LastAssigned:Blank()});
UpdateContext({var_LastCritAssigned:Blank()});
UpdateContext({var_Eng:!var_Eng});

So my thinking was, each time I click on a Sort above a specific Column, it would blank the other variables out, and sort that specific column Ascending or Descending, depending on true or false.

This was not working.

 

I am starting to think I have to change the items portion of the gallery WITH my sorting.

That is where I am getting lost.

Anyone help with setting this up?

I want to be able to sort by engineer type first to fill the gallery with those specific engineers.

Then, be able to sort the columns just by clicking on the specific Icons.  Not combing the sorting just either sort by Engineer, or Sort by Total Cases, etc.

 

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

    @lardo5150 

    Hi again (and yes, I still have your other post to respond to...will do shortly!)

    So, you have some things in your OnVisible formula that do nothing and will only slow down your app.

    Things like:

    If(!IsBlank(var_Eng),SortByColumns(Engineers,"EngineerDisplayName",If(var_Eng=true,Ascending, Descending)));

    Will actually do nothing.  SortByColumns returns a table, you are not using that table for anything nor assigning it to anything...so, it is just app cycles that are wasted.

     

    You don't need all of those variables for what you are trying to do.

     

    And, Yes, you will need to be focused on the Items property of your Gallery.

     

    In general, for the sort icons of your columns, you will have the following formula:

    With({_colName: "<columnNameHere>",
     _defaultSortAscending: true},
    
    UpdateContext({lclSortAscending: 
     If(lclSortColumn= _colName, !lclSortAscending, _defaultSortAscending)
    }
    );
    UpdateContext({lclSortColumn: "<columnName>"});
    

     

    Then your Gallery Items property would become:

    SortByColumns(Engineers,
     lclSortColumn,
     If(lclSortAscending, Ascending, Descending)
    )

     

    To avoid dealing with setting variables initially...change the formula to this:

    SortByColumns(Engineers,
     Coalesce(lclSortColumn, "<defaultSortColumn>"),
     If(Coalesce(lclSortAscending, true), Ascending, Descending)
    )

    Just replace the defaultSortColumn with the name of the column you want to sort by default.  And change true to false if you want descending by default.

     

    I hope this is helpful for you.

  • lardo5150 Profile Picture
    Microsoft Employee on at

    dude, you are a machine.

    I had to modify some of that to get it to work exactly how I wanted, but it is ALL working!

    I just "bought you a cup of coffee".... 🙂

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 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard