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 / Sort() not sorting Num...
Power Apps
Unanswered

Sort() not sorting Numbers correctly with a Switch() Statement

(1) ShareShare
ReportReport
Posted on by 2

Hi,

 

I am trying to have dynamic sorting, with complex types which is why SortByColumn() is not working.

 

My code basically is this:

 

 

Sort('Data';
Switch(lastSortFilter;
 "xy";'xy.DisplayName;
 "ID"; ID;
 "Title";Title;
 "Status";Status.Value;
 "abc";'abc'.Value;
)
 ; If(SortVar; Descending; Ascending))


	

 

 

The problem is, it is only working as text sort an breaks the sorting of the number columns. For Example ID gets sortet like this:

1
10
11

2

 

But ID is not a text column. If I change my Code to this:

 

Sort('Data';
ID
 ; If(SortVar; Descending; Ascending))

 

It sorts the way it should be. So 1, 2, [...], 10, 11.

 

So why is the Switch() function breaking the sort function and is there any workaround?

 

Thanks for any help

Categories:
I have the same question (0)
  • timl Profile Picture
    36,851 Super User 2026 Season 1 on at

    Hi @tryingPwer 

    The return value from Switch must always return a value with a consistant data type - in this case, a string.

    A workaround would be to format the id values with preceeding spaces using the Text function (eg, 00001, 00002, 00003) etc, and the sort should then work as expected.

    Sort('Data';
     Switch(lastSortFilter;
     "xy";'xy.DisplayName;
     "ID"; Text(ID;"00000#");
     "Title";Title;
     "Status";Status.Value;
     "abc";'abc'.Value;
     );
     If(SortVar; Descending; Ascending)
    )
    

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,027

#2
Valantis Profile Picture

Valantis 644

#3
11manish Profile Picture

11manish 626

Last 30 days Overall leaderboard