web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sorting Records on Ser...
Power Apps
Unanswered

Sorting Records on Serial Number in Ascending and Descending Order, on a Button Click

(0) ShareShare
ReportReport
Posted on by 1,057

App DisplayApp DisplaySort_Button_CodeSort_Button_CodeBrowseGallery_CodeBrowseGallery_CodeHello,

 

I am trying to Sort my records by Serial number like 1,2,3... in ascending and Descending order ( Last to 1st) record.

 

But I am facing a little problem there, It's sorting in ascending and descending order but not what I wanted.

Problem: 1,10,11,12... 2,20,23... (sorting in this format).

 

Attaching Screenshots for your reference.

Kindly Help

@MHD @PHE @Anonymous 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @MH3 

    Your serial number is likely a text value.  A text value sorts in the order:

    1, 10, 11, 12, 2, 20, 23

     

    Instead, you should change your serial number to a number value in the data source.  The result will be:

    1, 2, 10, 11, 12, 20, 23

     

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

  • Verified answer
    Pstork1 Profile Picture
    68,707 Most Valuable Professional on at

    If changing the serial number field to an integer as @mdevaney suggests isn't feasible you might also try using Sort() with a Value() function for the expression.  That would convert the alpha serial number to a number as part of the sort.  The one problem is that the value() expression isn't delegable so it won't work with a large number of records.

    Sort(DataSource,Value('Serial Number'))
  • MH3 Profile Picture
    1,057 on at

    Dear @mdevaney ,

     

    I have tried everything, changed the serial number to Nmber Format, but still I can't get the solution.

     

     

    Please help

  • MH3 Profile Picture
    1,057 on at
    Sort(DataSource,Value('Serial Number')),if(SortDescending1, Descending, Ascending))
    ??? 
    
    Do, I have to write this code, in order to use the Sort Button?
  • MH3 Profile Picture
    1,057 on at

    Dear @Pstork1 ,

     

    It is sorted but, the Sort Button is not working and its not performing Ascending and Descending Sort..

     

    Kindly Help

     

    Srorted.JPG

  • Pstork1 Profile Picture
    68,707 Most Valuable Professional on at

    Yes, you have to put code in the OnSelect for the Sort button.  Also, you need to make sure that the gallery is sorting on numeric values and not string values.  Numbers will sort differently than strings. The correct code should be:

     

    Sort(DataSource,Value('Serial Number'),if(SortDescending1, Descending, Ascending));Set(SortDescending1, not(SortDescending1))

     

    You had an extra closing Parentheses. You'll also need something to set SortDescending1 when you flip it.

  • MH3 Profile Picture
    1,057 on at

    Dear @Pstork1 ,

     

    I am sorry, it's still not working 

    Sort('P.A.A.S. ',Value("S_x002e__x0020__x0023_"), If(SortDescending1, Descending, Ascending));
    Set(SortDescending1, Not(SortDescending1))

     

    It says you can't use Not in the APP.

     

    Help

    Not_working.jpg

  • mdevaney Profile Picture
    29,989 Moderator on at

    @MH3 

    SET cannot be used in the Items property of the app.  I believe @Pstork1 said to use it in the OnSelect property.

  • MH3 Profile Picture
    1,057 on at

     @mdevaney Yes, I have used in the OnSelect Property, but still no progress.

     SortByColumns(Search('P.A.A.S. ', TextSearchBox1.Text,"S_x002e__x0020__x0023_"),
    "S_x002e__x0020__x0023_", If(SortDescending1, Descending, Ascending))

     

    Currently using this code, but the sorting is like 1,10,100,101,11,12... which is wrong, although I have changed the TextSearchBox Format into "Number". 

     

    Kindly Help

     

  • Pstork1 Profile Picture
    68,707 Most Valuable Professional on at

    Good Catch @mdevaney .  The Sort goes in the items property of the gallery and the set goes in the sort icon button's onselect.  When you click the button it switches the ascending/descending property True/False.  That change should re-sort the gallery.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard