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 Sort by drop-do...
Power Apps
Answered

How to Sort by drop-down category

(2) ShareShare
ReportReport
Posted on by 31
Hello, I would like to sort my data using "Asset Category" and display it like the image below:
 
The image below is sorted using "Asset No" with no drop-down selection. I want to sort using "Asset Category". May I know how do I go about doing this?
 
Currently this is the code I am using:
 
SortByColumns(
    AddColumns(
        Filter(
            [@'FSC Assets Management'],
            StartsWith('Asset No', "SFSC-FZ")
        ),
        Suffix,
        Value(Last(Split(ThisRecord.'Asset No',"-")).Value)
    ),
    "Suffix",
    If(SortDescending1, SortOrder.Descending, SortOrder.Ascending)
)

 
 
Categories:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    156,267 Most Valuable Professional on at
    I may be missing something here, but the Sort field can be changed to whatever you want. What is the drop-down you are referring to ?​​​​​​
    SortByColumns(
       AddColumns(
          Filter(
             [@'FSC Assets Management'],
             StartsWith('Asset No', "SFSC-FZ")
          ),
          Suffix,
          Value(Last(Split(ThisRecord.'Asset No',"-")).Value)
       ),
       "Asset Category",
       If(
          SortDescending1, 
          SortOrder.Descending, 
          SortOrder.Ascending
    )
     
    Please Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Justinn111_ Profile Picture
    31 on at
    Hi @WarrenBelz, appreciate your help here.
     
    If you can see from my screenshot below, Under my Asset Category, I have "Supporting Equipment - No Service Required" and "Supporting Equipment - Service Required".
     
     
     
    ie. I want it to be displayed in a table like after I click on "Supporting Equipment (FZ/SES)", it should bring me to the page where it display the "Asset No", based on the Asset Category of "Supporting Equipment - Service Required" 
     
    I hope this is clearer. I am sorry if my explanation is bad.
     
                                
     
  • Verified answer
    MS.Ragavendar Profile Picture
    7,613 Super User 2026 Season 2 on at
     
    Based on the post whatever @WarrenBelz suggested will works but with your recent post some points varies.
     
    Property (On Select ) of the each button if its individual controls
     
     
    Set(varAssetCategory,"Supporting Equipment - No Service Required");
    Navigate(scrAssetList); // Navigate to the relevant screen
     
    Items Property of the Gallery
     
    SortByColumns(
        AddColumns(
            Filter(
                'FSC Assets Management',
                'Asset Category'.Value = varAssetCategory
            ),
            Suffix,
            Value(
                Last(
                    Split('Asset No', "-")
                ).Value
            )
        ),
        "Suffix",
        SortOrder.Ascending
    )
    Note : 
    I assume Asset Category as choice column so provided as columnName.Value.
    Similarly please replace with the respective datasource and columns which you are using in the system.
     
    ✅If this helped, please Accept as Solution to help others ❤️ A Like is appreciated 🏷️ Tag @MS.Ragavendar for follow-ups.

     

  • Justinn111_ Profile Picture
    31 on at
     
    Thanks! It works! I have one last question. 
     
    Using your solution in the response above (Items Property of the Gallery), what do I need to put in to make it display only "SFSC-FZ"? I want to display the list for "SFSC-FZ-XX" only.
     
    I do not need the "CD-CB-XX" like shown in the screenshot below.
     
  • Verified answer
    WarrenBelz Profile Picture
    156,267 Most Valuable Professional on at
     
    EDIT - I was preparing this post while you were doing the last one and did not see it until now. The below may answer your question.
     
    Firstly @MS.Ragavendar is on the right track and that may be all you need. I am assuming you may need the two "suffix" values in your data set, so firstly OnSelect of your button 
    UpdateContext({varCat: "Service Required"})
    and then your Gallery Items
    SortByColumns(
       Filter(
          AddColumns(
             [@'FSC Assets Management'],
             NoSuffix,
             Value(Last(Split('Asset No',"-")).Value),
             CatSuffix,
             Last(Split('Asset Category')).Value
          ),
          StartsWith('Asset No', "SFSC-FZ") &&
          catSuffix = varCat	  
       ),
       "CatSuffix",
       If(
          SortDescending1, 
          SortOrder.Descending, 
          SortOrder.Ascending
       )
    )
     
    Please Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Verified answer
    MS.Ragavendar Profile Picture
    7,613 Super User 2026 Season 2 on at
     
    You have to include the StartsWith with the respective column.
    SortByColumns(
        AddColumns(
            Filter(
                'FSC Assets Management',
                'Asset Category'.Value = varAssetCategory &&
                StartsWith('Asset No', "SFSC-FZ")
            ),
            Suffix,
            Value(
                Last(
                    Split('Asset No', "-")
                ).Value
            )
        ),
        "Suffix",
        SortOrder.Ascending
    )
    Note :
    • Currently I have hardcoded this StartsWith('Asset No', "SFSC-FZ") it can be rewrite dynamic as well.
    • On the Button click how we are setting the varAssetCategory similarly you can also set varAssetPrefix
    Set(varAssetPrefix,"SFSC-FZ") and this variable has to provided in the StartsWith('Asset No', varAssetPrefix)
     
    ✅If this helped, please Accept as Solution to help others ❤️ A Like is appreciated 🏷️ Tag @MS.Ragavendar for follow-ups.
  • Suggested answer
    Raghav Mishra Profile Picture
    277 Super User 2026 Season 2 on at

    Hi @Justinn111_, you are very close - the issue is the sort key and, if you stay with SortByColumns, the way the column name has to be written.

    Sorting by two keys

    Microsoft Learn's documented pattern for sorting by one column and then another is to nest Sort inside Sort, for example Sort( Sort( Contacts, LastName ), FirstName ) to sort first by LastName and then by FirstName. Applied to your gallery, with Asset Category as the primary key and your numeric suffix as the secondary:

    Sort(
        Sort(
            AddColumns(
                Filter( [@'FSC Assets Management'], StartsWith('Asset No', "SFSC-FZ") ),
                Suffix, Value( Last( Split( ThisRecord.'Asset No', "-" ) ).Value )
            ),
            'Asset Category'
        ),
        Suffix,
        If( SortDescending1, SortOrder.Descending, SortOrder.Ascending )
    )

    Sort takes a formula rather than a string, so you can reference the column directly and the ThisRecord operator is available inside it.

    If you keep SortByColumns - watch the space in the column name

    This is the detail that catches most people out. Learn is explicit: for SharePoint and Excel data sources, a column name containing a space must have each space specified as _x0020_. So "Asset Category" has to be written as:

    SortByColumns( YourTable, "Asset_x0020_Category" )

    Passing a plain "Asset Category" string is the usual reason SortByColumns appears to do nothing at all.

    Driving it from the drop-down

    Populate the drop-down with Distinct( 'FSC Assets Management', 'Asset Category' ) and use the selection to filter the gallery, keeping the sort above to control ordering within each category.

    One caution on delegation

    AddColumns combined with Value(Split(...)) is not delegable, so the sort only ever evaluates the rows that have already been pulled into the app. If the list is larger than your data row limit you will get inconsistent ordering. Check the delegation warnings in the formula bar and consider storing the numeric suffix as its own SharePoint column so the sort can be delegated.

    References

    Found this helpful? Please mark ✅ "Does this answer your question?" so others searching for the same issue can find it quickly. A 👍 on "Was this reply helpful?" or a ♥ Like is also much appreciated!

    Raghav Mishra - LinkedIn| PowerAI Labs

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

#2
11manish Profile Picture

11manish 159 Super User 2026 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 89 Super User 2026 Season 2

Last 30 days Overall leaderboard