cancel
Showing results for
Did you mean:
Post Prodigy

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

App DisplaySort_Button_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).

Kindly Help

2 ACCEPTED SOLUTIONS

Accepted Solutions
Dual Super User

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 you like my response, please give it a Thumbs Up.
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 you like my response, please give it a Thumbs Up.
15 REPLIES 15
Super User

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

Dual Super User

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 you like my response, please give it a Thumbs Up.
Post Prodigy

Dear @mdevaney ,

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

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

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

Dear @Pstork1 ,

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

Kindly Help

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 you like my response, please give it a Thumbs Up.
Post Prodigy

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

Super User

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

Post Prodigy

@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

Announcements

#### 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.

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