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 / SortByColumns using Co...
Power Apps
Unanswered

SortByColumns using ComboBox values to determine the Columns

(0) ShareShare
ReportReport
Posted on by 85

Hello all, 

I'm trying to a complicated sort. I feel like this post https://powerusers.microsoft.com/t5/Building-Power-Apps/Sorting-Gallery-by-selecting-column-from-ComboBox/td-p/801611 gets me close but I'm not sure I understand it completely. @jbrit2020  maybe you can help me understand the solution you provided? 

 

Screen 1: User selects items > these items get put into a collection

Screen 2: ComboBox default selected items is the collection from screen 1. 

On Screen 2 I have a gallery that filters based on several factors with one being the previously mentioned ComboBox. 

 

I would like to sort my results in the Gallery based on columns that match the names in the ComboBox. The columns are Text Columns that have either "Protected", "Compatible", "Not Protected".

 

Right now I have a formula that will sort the results but by all columns and not only the ones listed in the ComboBox (cbmetals). This currently doesn't help sort the results in a useable way. I want to sort the results to have those with "Protected" in the columns listed first, followed by "Compatible".

 

Current Formula Part 1

Miss_Zo_0-1704829386237.png

Part 2

Miss_Zo_1-1704829437805.png

 

Do I have to do If statements for each column? So If Cast Iron in cbmetals then x, y, z? Then do that for every one? 

 

 

 

 

 

 

 

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Miss_Zo ,

     

    You can use a Switch function in SortByColumns. The second param of this function needs static column names, so:

    Switch(cbmetals.Selected.Value, "Protected", "Protected", "Compatible", "Compatible", "Not Protected", "Not Protected")

     

    Best regards,

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    I can put in the Switch function and I don't get an error, however it also is not sorting the results. 

    This is my first time using the Switch function, so please let me know if I'm doing so incorrectly. 

     

    Same part 1 photo as in the original post. 

    Part 2

    Miss_Zo_0-1704986879077.png

     

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Miss_Zo ,

     

    Your formula is using correctly. But as you can see there is delegation warning, if the result items of Filter function were much more than data row limit, sort function would not work as expected. Please increase data row limit to maximum 2000 and try again. 

     

    Also, you can try and use Sort function instead, but then you will need to modify the Switch funtion:

    Switch(cbmetals.Selected.Value, "Protected", Protected, "Compatible", Compatible, "Not Protected", 'Not Protected')

     

    Best regards,

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    Thanks. This does not solve the issue. I think there's a disconnect between the value in the combobox and the column. I was thinking maybe I need to have a LookUpColumnName or some other lookup function so it knows that the value in the combobox matches the title of the column. Then to find if the column shows "Protected" it sorts the gallery list by those first. 

     

    Do you know if we can combine Switch and Lookup? 

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    Do I need to use something more like this? https://powerusers.microsoft.com/t5/Building-Power-Apps/Sorting-Gallery-by-selecting-column-from-ComboBox/td-p/801611

     

    With function creating and IF condition and tempory variable? Not sure how. 

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Miss_Zo ,

     

    The With function will only eliminate delegation warning from your App but the issue will persist on backend. If you want to give it a try, you can post your formula in Text so that I can help you with the modifications.

     

    Best regards,

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    Hmmm. Delegation isn't my issue. I think it is getting it to recognize that items selected are columns and to search those columns. I'll keep trying. 

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    This is what I'm thinking, but I'm getting an error. Having something that is If(IsMatch......) for each column. 

    Miss_Zo_0-1705343935199.png

     

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @Miss_Zo ,

     

    I made a sample for your reference. Both methods work as expected except for the delegation issue.

    Using SortByColumns:

    vjefferni_0-1705399960482.png

    Using Sort:

    vjefferni_1-1705400012196.png

     

    Best regards,

  • Miss_Zo Profile Picture
    85 on at

    @v-jefferni 

    That seems to work for one value. I have a combobox that can have multiple values. It seems to have to be combobox.SelectedItems. 

     

    I need to be able to match the multiple values in the combobox to Column titles in my sharepoint list, and then filter based on the text in that column for each product. 

     

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 333 Most Valuable Professional

#2
11manish Profile Picture

11manish 184

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 86 Super User 2026 Season 1

Last 30 days Overall leaderboard