cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MH3
Post Prodigy
Post Prodigy

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

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 @Power 

2 ACCEPTED SOLUTIONS

Accepted Solutions

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'))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Pstork1
Dual Super User
Dual Super User

I'm tied up with something right now, but I could join a session in about 30 minutes Noon Eastern Time (USA).



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

15 REPLIES 15
mdevaney
Super User
Super User

@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." 

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'))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Dear @mdevaney ,

 

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

 

 

Please help

Sort(DataSource,Value('Serial Number')),if(SortDescending1, Descending, Ascending))
??? 

Do, I have to write this code, in order to use the Sort Button?
MH3
Post Prodigy
Post Prodigy

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
Dual Super User
Dual Super User

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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

@MH3 

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

 @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

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (4,458)